MemberComponent fix, better error handling

This commit is contained in:
Norbi Peti 2019-08-18 18:20:50 +02:00
parent 2ad7a757c6
commit feee6a0ebe
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 14 additions and 3 deletions

View file

@ -24,7 +24,7 @@ public final class ComponentManager {
Component.getComponents().values().stream().filter(c -> c.shouldBeEnabled().get()).forEach(c -> {
try {
Component.setComponentEnabled(c, true);
} catch (Exception e) {
} catch (Exception | NoClassDefFoundError e) {
TBMCCoreAPI.SendException("Failed to enable one of the components: " + c.getClass().getSimpleName(), e);
}
});

View file

@ -10,6 +10,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.AbstractMap;
import java.util.Date;
import static buttondevteam.core.MainPlugin.permission;
@ -39,10 +40,17 @@ public class MemberComponent extends Component<MainPlugin> implements Listener {
return getConfig().getData("registeredForDays", 7);
}
private AbstractMap.SimpleEntry<Statistic, Integer> playtime;
@Override
protected void enable() {
registerListener(this);
registerCommand(new MemberCommand(this));
try {
playtime = new AbstractMap.SimpleEntry<>(Statistic.valueOf("PLAY_ONE_MINUTE"), 60); //1.14
} catch (IllegalArgumentException e) {
playtime = new AbstractMap.SimpleEntry<>(Statistic.valueOf("PLAY_ONE_TICK"), 20 * 3600); //1.12
}
}
@Override
@ -53,7 +61,7 @@ public class MemberComponent extends Component<MainPlugin> implements Listener {
public void onPlayerJoin(PlayerJoinEvent event) {
if (permission != null && !permission.playerInGroup(event.getPlayer(), memberGroup().get())
&& (new Date(event.getPlayer().getFirstPlayed()).toInstant().plus(registeredForDays().get(), ChronoUnit.DAYS).isBefore(Instant.now())
|| event.getPlayer().getStatistic(Statistic.PLAY_ONE_TICK) > 20 * 3600 * playedHours().get())) {
|| event.getPlayer().getStatistic(playtime.getKey()) > playtime.getValue() * playedHours().get())) {
if (permission.playerAddGroup(null, event.getPlayer(), memberGroup().get())) {
event.getPlayer().sendMessage("§bYou are a member now. YEEHAW");
MainPlugin.Instance.getLogger().info("Added " + event.getPlayer().getName() + " as a member.");
@ -62,4 +70,5 @@ public class MemberComponent extends Component<MainPlugin> implements Listener {
}
}
}
}

View file

@ -127,6 +127,7 @@ public class TBMCCoreAPI {
}
}
private static EventExceptionCoreHandler eventExceptionCoreHandler;
/**
* Registers Bukkit events, handling the exceptions occurring in those events
*
@ -134,7 +135,8 @@ public class TBMCCoreAPI {
* @param plugin The plugin which the listener belongs to
*/
public static void RegisterEventsForExceptions(Listener listener, Plugin plugin) {
EventExceptionHandler.registerEvents(listener, plugin, new EventExceptionCoreHandler());
if (eventExceptionCoreHandler == null) eventExceptionCoreHandler = new EventExceptionCoreHandler();
EventExceptionHandler.registerEvents(listener, plugin, eventExceptionCoreHandler);
}
public static <T extends ChromaGamerBase> void RegisterUserClass(Class<T> userclass) {