diff --git a/src/com/massivecraft/massivecore/MassiveCore.java b/src/com/massivecraft/massivecore/MassiveCore.java index 773f0876..1a4abe07 100644 --- a/src/com/massivecraft/massivecore/MassiveCore.java +++ b/src/com/massivecraft/massivecore/MassiveCore.java @@ -230,7 +230,7 @@ public class MassiveCore extends MassivePlugin public List> getClassesActiveColls() { List> ret = this.getClassesActive(null, Coll.class); - + if (!ret.contains(MassiveCoreMConfColl.get().getClass())) ret.add(0, MassiveCoreMConfColl.get().getClass()); return ret; } diff --git a/src/com/massivecraft/massivecore/MassiveCoreMConf.java b/src/com/massivecraft/massivecore/MassiveCoreMConf.java index b6fdd6d1..c5a5a28c 100644 --- a/src/com/massivecraft/massivecore/MassiveCoreMConf.java +++ b/src/com/massivecraft/massivecore/MassiveCoreMConf.java @@ -175,14 +175,6 @@ public class MassiveCoreMConf extends Entity public boolean debugEnabled = false; - // -------------------------------------------- // - // SPONSOR - // -------------------------------------------- // - // URL connections to http://sponsorinfo.massivecraft.com/ - - public long sponsorUpdateMillis = 0; - public boolean sponsorEnabled = true; - // -------------------------------------------- // // METRICS // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/MassiveCoreMSponsorInfo.java b/src/com/massivecraft/massivecore/MassiveCoreMSponsorInfo.java deleted file mode 100644 index e78a62a0..00000000 --- a/src/com/massivecraft/massivecore/MassiveCoreMSponsorInfo.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.massivecraft.massivecore; - -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.store.Entity; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; -import com.massivecraft.massivecore.util.WebUtil; -import org.bukkit.Bukkit; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; - -public class MassiveCoreMSponsorInfo extends Entity -{ - // -------------------------------------------- // - // META - // -------------------------------------------- // - - protected static transient MassiveCoreMSponsorInfo i; - public static MassiveCoreMSponsorInfo get() { return i; } - - // -------------------------------------------- // - // COMMON - // -------------------------------------------- // - - public boolean enabled = true; - - public long enabledToMillis = 2473890400000L; - - public List indicatorFileNames = new MassiveList<>( - "/home/smpicnic" - ); - - // -------------------------------------------- // - // CONSOLE - // -------------------------------------------- // - - public boolean consoleEnabled = true; - - public int consoleDelayTicks = 100; - - public List consoleMsgs = new MassiveList<>( - "", - "____----====[ Sponsored by ServerMiner ]====----____", - "Get 20% off a Premium Factions Server at ServerMiner:", - "https://ServerMiner.com/plugins/Factions-Server-Hosting?p=MassiveCraft", - "", - "Factions and MassiveCore is sponsored by ServerMiner.com!", - "They help us fund the development of new plugin features.", - "", - "Only server operators get this message, not regular players.", - "Type /mcore sponsor to disable it.", - "" // NOTE: an empty line like this makes sense in console but not for players. - ); - - // -------------------------------------------- // - // INGAME - // -------------------------------------------- // - - public boolean ingameEnabled = true; - - public int ingameDelayTicks = 600; - - public List ingameMsgs = new MassiveList<>( - "", - "____----====[ Sponsored by ServerMiner ]====----____", - "Get 20% off a Premium Factions Server at ServerMiner:", - "https://ServerMiner.com/plugins/Factions-Server-Hosting?p=MassiveCraft", - "", - "Factions and MassiveCore is sponsored by ServerMiner.com!", - "They help us fund the development of new plugin features.", - "", - "Only server operators get this message, not regular players.", - "Type /mcore sponsor to disable it." - ); - - public List ingameSoundEffects = new MassiveList<>( - SoundEffect.valueOf( - "ENTITY_PLAYER_LEVELUP", - 1.0F, - 0.8F - ), - SoundEffect.valueOf( - "ENTITY_EXPERIENCE_ORB_PICKUP", - 1.0F, - 0.8F - ) - ); - - public String ingameLink = "https://ServerMiner.com/plugins/Factions-Server-Hosting?p=MassiveCraft"; - - // -------------------------------------------- // - // UPDATE - // -------------------------------------------- // - - public static final transient long SPONSOR_INFO_UPDATE_MILLIS = TimeUnit.MILLIS_PER_HOUR; - public static final transient URL SPONSOR_INFO_URL; - static - { - URL url = null; - try - { - url = new URL("http://sponsorinfo.massivecraft.com/2/"); - } - catch (MalformedURLException e) - { - e.printStackTrace(); - } - SPONSOR_INFO_URL = url; - } - - public static void update() - { - // If enough time has passed since last update ... - long now = System.currentTimeMillis(); - long last = MassiveCoreMConf.get().sponsorUpdateMillis; - long since = now - last; - if (since < SPONSOR_INFO_UPDATE_MILLIS) return; - - // ... then mark update ... - MassiveCoreMConf.get().sponsorUpdateMillis = now; - MassiveCoreMConf.get().changed(); - - // ... and start the update. - updateInner(); - } - - public static void updateInner() - { - Bukkit.getScheduler().runTaskAsynchronously(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - List lines; - try - { - lines = WebUtil.getLines(SPONSOR_INFO_URL); - } - catch (IOException e) - { - e.printStackTrace(); - return; - } - final String json = Txt.implode(lines, "\n"); - Bukkit.getScheduler().runTask(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - MassiveCoreMSponsorInfo web = MassiveCore.get().getGson().fromJson(json, MassiveCoreMSponsorInfo.class); - MassiveCoreMSponsorInfo live = MassiveCoreMSponsorInfo.get(); - live.load(web); - live.changed(); - } - }); - } - }); - } - -} diff --git a/src/com/massivecraft/massivecore/MassiveCoreMSponsorInfoColl.java b/src/com/massivecraft/massivecore/MassiveCoreMSponsorInfoColl.java deleted file mode 100644 index 6685d830..00000000 --- a/src/com/massivecraft/massivecore/MassiveCoreMSponsorInfoColl.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.massivecraft.massivecore; - -import com.massivecraft.massivecore.store.Coll; - -public class MassiveCoreMSponsorInfoColl extends Coll -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MassiveCoreMSponsorInfoColl i = new MassiveCoreMSponsorInfoColl(); - public static MassiveCoreMSponsorInfoColl get() { return i; } - private MassiveCoreMSponsorInfoColl() - { - super("massivecore_msponsorinfo"); - } - - // -------------------------------------------- // - // STACK TRACEABILITY - // -------------------------------------------- // - - @Override - public void onTick() - { - super.onTick(); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActive(boolean active) - { - super.setActive(active); - - if ( ! active) return; - - MassiveCoreMSponsorInfo.i = this.get(MassiveCore.INSTANCE, true); - } - -} diff --git a/src/com/massivecraft/massivecore/MassivePlugin.java b/src/com/massivecraft/massivecore/MassivePlugin.java index ecd10c7d..3e562ac9 100644 --- a/src/com/massivecraft/massivecore/MassivePlugin.java +++ b/src/com/massivecraft/massivecore/MassivePlugin.java @@ -215,7 +215,7 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name // can only happen after others have been initialised. public void activateOne(Object object) { - boolean debug = MassiveCoreMConf.get() != null && MassiveCoreMConf.get().debugEnabled; + boolean debug = true;//MassiveCoreMConf.get() != null && MassiveCoreMConf.get().debugEnabled; // Try collection if (object instanceof Iterable) @@ -425,22 +425,8 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name packageName = this.getClass().getPackage().getName() + packageName; Predicate predicateCombined = PredicateAnd.get(predicates); - Predicate> predicateNotAbstract = new Predicate>() - { - @Override - public boolean apply(Class type) - { - return !Modifier.isAbstract(type.getModifiers()); - } - }; - Predicate> predicateSubclass = new Predicate>() - { - @Override - public boolean apply(Class type) - { - return superClass.isAssignableFrom(type); - } - }; + Predicate> predicateNotAbstract = type -> !Modifier.isAbstract(type.getModifiers()); + Predicate> predicateSubclass = type -> !Modifier.isAbstract(type.getModifiers()); Predicate> predicateSingleton = PredicateIsClassSingleton.get(); return ReflectionUtil.getPackageClasses(packageName, this.getClassLoader(), true, predicateCombined, predicateNotAbstract, predicateSubclass, predicateSingleton); diff --git a/src/com/massivecraft/massivecore/cmd/CmdMassiveCore.java b/src/com/massivecraft/massivecore/cmd/CmdMassiveCore.java index 062e9337..c7162f33 100755 --- a/src/com/massivecraft/massivecore/cmd/CmdMassiveCore.java +++ b/src/com/massivecraft/massivecore/cmd/CmdMassiveCore.java @@ -31,7 +31,6 @@ public class CmdMassiveCore extends MassiveCoreCommand public CmdMassiveCoreBuffer cmdMassiveCoreBuffer = new CmdMassiveCoreBuffer(); public CmdMassiveCoreCmdurl cmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl(); public CommandEditAbstract cmdMassiveCoreConfig = new CommandEditSingleton<>(MassiveCoreMConf.get()).addRequirements(RequirementHasPerm.get(MassiveCorePerm.CONFIG)); - public CmdMassiveCoreSponsor cmdMassiveCoreSponsor = new CmdMassiveCoreSponsor(); public CmdMassiveCoreClick cmdMassiveCoreClick = new CmdMassiveCoreClick(); public MassiveCommandVersion cmdMassiveCoreVersion = new MassiveCommandVersion(MassiveCore.get()).setAliases("v", "version").addRequirements(RequirementHasPerm.get(MassiveCorePerm.VERSION)); diff --git a/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreSponsor.java b/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreSponsor.java deleted file mode 100755 index 7f5010b0..00000000 --- a/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreSponsor.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.massivecraft.massivecore.cmd; - -import com.massivecraft.massivecore.MassiveCoreMConf; -import com.massivecraft.massivecore.MassiveCorePerm; -import com.massivecraft.massivecore.command.MassiveCommandToggle; -import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; - -public class CmdMassiveCoreSponsor extends MassiveCommandToggle -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static CmdMassiveCoreSponsor i = new CmdMassiveCoreSponsor(); - public static CmdMassiveCoreSponsor get() { return i; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdMassiveCoreSponsor() - { - // Aliases - this.addAliases("sponsor"); - - // Requirements - this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.SPONSOR)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean getValue() - { - return MassiveCoreMConf.get().sponsorEnabled; - } - - @Override - public void setValue(boolean value) - { - MassiveCoreMConf.get().sponsorEnabled = value; - MassiveCoreMConf.get().changed(); - } - -} diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreSponsor.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreSponsor.java deleted file mode 100644 index ffe266f4..00000000 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreSponsor.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.massivecraft.massivecore.engine; - -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.MassiveCore; -import com.massivecraft.massivecore.MassiveCoreMConf; -import com.massivecraft.massivecore.MassiveCoreMSponsorInfo; -import com.massivecraft.massivecore.SoundEffect; -import com.massivecraft.massivecore.mixin.MixinDisplayName; -import com.massivecraft.massivecore.mixin.MixinMessage; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; - -import java.io.File; -import java.io.InputStream; -import java.util.List; -import java.util.Scanner; - -public class EngineMassiveCoreSponsor extends Engine -{ - // -------------------------------------------- // - // CONSTANT - // -------------------------------------------- // - - private static final String DISABLE_CODE = readDisableCode(); - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineMassiveCoreSponsor i = new EngineMassiveCoreSponsor(); - public static EngineMassiveCoreSponsor get() { return i; } - public EngineMassiveCoreSponsor() - { - this.setPeriod(1L); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActiveInner(boolean active) - { - if ( ! active) return; - - // We delay informing the console. - // This is because the console may not exist when this engine is activated. - Bukkit.getScheduler().runTask(this.getPlugin(), new Runnable() - { - @Override - public void run() - { - ConsoleCommandSender console = IdUtil.getConsole(); - inform(console); - } - }); - } - - // -------------------------------------------- // - // UPDATE - // -------------------------------------------- // - - @Override - public void run() - { - // If enabled ... - if ( ! this.isEnabled()) return; - - // ... update sponsor info. - MassiveCoreMSponsorInfo.update(); - } - - // -------------------------------------------- // - // ENABLED - // -------------------------------------------- // - - private static String readDisableCode() { - InputStream inputStream = MassiveCore.get().getResource("sponsor-disable-code"); - Scanner scanner = new Scanner(inputStream).useDelimiter("\\A"); - return scanner.hasNext() ? scanner.next().trim() : ""; - } - - private boolean isEnabled() - { - // NOTE: Uncomment to make use of disable code system. - return MassiveCoreMConf.get().sponsorEnabled;// && DISABLE_CODE.hashCode() != 644515031; - } - - private boolean isEnabled(final CommandSender sender) - { - // If there is a sender ... - if (sender == null) return false; - - // ... and enabled ... - if ( ! this.isEnabled()) return false; - - // ... and enabled by info base ... - if ( ! MassiveCoreMSponsorInfo.get().enabled) return false; - - // ... and enabled by info time ... - long now = System.currentTimeMillis(); - long to = MassiveCoreMSponsorInfo.get().enabledToMillis; - long left = to - now; - if (left <= 0) return false; - - // ... and enabled by sender type ... - boolean enabledByType = (IdUtil.isConsole(sender) ? MassiveCoreMSponsorInfo.get().consoleEnabled : MassiveCoreMSponsorInfo.get().ingameEnabled); - if ( ! enabledByType) return false; - - // ... and enabled by sender operator ... - if ( ! sender.isOp()) return false; - - // ... and enabled by in indicator files ... - for (String indicatorFileName : MassiveCoreMSponsorInfo.get().indicatorFileNames) - { - File indicatorFile = new File(indicatorFileName); - if (indicatorFile.exists()) return false; - } - - // ... then it's actually enabled. - return true; - } - - // -------------------------------------------- // - // INFORM - // -------------------------------------------- // - - public void inform(final CommandSender sender) - { - // Enabled - if ( ! this.isEnabled(sender)) return; - - // Schedule - int delayTicks = (IdUtil.isConsole(sender) ? MassiveCoreMSponsorInfo.get().consoleDelayTicks : MassiveCoreMSponsorInfo.get().ingameDelayTicks); - Bukkit.getScheduler().runTaskLater(this.getPlugin(), new Runnable() - { - @Override - public void run() - { - informInner(sender); - } - }, delayTicks); - } - - public void informInner(CommandSender sender) - { - // Enabled - if ( ! this.isEnabled(sender)) return; - - // Messages - List msgs = (IdUtil.isConsole(sender) ? MassiveCoreMSponsorInfo.get().consoleMsgs : MassiveCoreMSponsorInfo.get().ingameMsgs); - String senderVisual = MixinDisplayName.get().getDisplayName(sender, sender); - for (String msg : msgs) - { - String message = Txt.parse(msg); - message = message.replace("{p}", senderVisual); - Mson mson = Mson.fromParsedMessage(message).link(MassiveCoreMSponsorInfo.get().ingameLink); - MixinMessage.get().messageOne(sender, mson); - } - - // Sound - if (sender instanceof Player) - { - Player player = (Player)sender; - SoundEffect.runAll(MassiveCoreMSponsorInfo.get().ingameSoundEffects, player); - } - } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - this.inform(player); - } - -}