MemberComponent fix, better error handling
This commit is contained in:
parent
2ad7a757c6
commit
feee6a0ebe
3 changed files with 14 additions and 3 deletions
|
@ -24,7 +24,7 @@ public final class ComponentManager {
|
||||||
Component.getComponents().values().stream().filter(c -> c.shouldBeEnabled().get()).forEach(c -> {
|
Component.getComponents().values().stream().filter(c -> c.shouldBeEnabled().get()).forEach(c -> {
|
||||||
try {
|
try {
|
||||||
Component.setComponentEnabled(c, true);
|
Component.setComponentEnabled(c, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception | NoClassDefFoundError e) {
|
||||||
TBMCCoreAPI.SendException("Failed to enable one of the components: " + c.getClass().getSimpleName(), e);
|
TBMCCoreAPI.SendException("Failed to enable one of the components: " + c.getClass().getSimpleName(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static buttondevteam.core.MainPlugin.permission;
|
import static buttondevteam.core.MainPlugin.permission;
|
||||||
|
@ -39,10 +40,17 @@ public class MemberComponent extends Component<MainPlugin> implements Listener {
|
||||||
return getConfig().getData("registeredForDays", 7);
|
return getConfig().getData("registeredForDays", 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AbstractMap.SimpleEntry<Statistic, Integer> playtime;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enable() {
|
protected void enable() {
|
||||||
registerListener(this);
|
registerListener(this);
|
||||||
registerCommand(new MemberCommand(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
|
@Override
|
||||||
|
@ -53,7 +61,7 @@ public class MemberComponent extends Component<MainPlugin> implements Listener {
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (permission != null && !permission.playerInGroup(event.getPlayer(), memberGroup().get())
|
if (permission != null && !permission.playerInGroup(event.getPlayer(), memberGroup().get())
|
||||||
&& (new Date(event.getPlayer().getFirstPlayed()).toInstant().plus(registeredForDays().get(), ChronoUnit.DAYS).isBefore(Instant.now())
|
&& (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())) {
|
if (permission.playerAddGroup(null, event.getPlayer(), memberGroup().get())) {
|
||||||
event.getPlayer().sendMessage("§bYou are a member now. YEEHAW");
|
event.getPlayer().sendMessage("§bYou are a member now. YEEHAW");
|
||||||
MainPlugin.Instance.getLogger().info("Added " + event.getPlayer().getName() + " as a member.");
|
MainPlugin.Instance.getLogger().info("Added " + event.getPlayer().getName() + " as a member.");
|
||||||
|
@ -62,4 +70,5 @@ public class MemberComponent extends Component<MainPlugin> implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ public class TBMCCoreAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static EventExceptionCoreHandler eventExceptionCoreHandler;
|
||||||
/**
|
/**
|
||||||
* Registers Bukkit events, handling the exceptions occurring in those events
|
* 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
|
* @param plugin The plugin which the listener belongs to
|
||||||
*/
|
*/
|
||||||
public static void RegisterEventsForExceptions(Listener listener, Plugin plugin) {
|
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) {
|
public static <T extends ChromaGamerBase> void RegisterUserClass(Class<T> userclass) {
|
||||||
|
|
Loading…
Reference in a new issue