diff --git a/src/com/massivecraft/massivecore/MassivePlugin.java b/src/com/massivecraft/massivecore/MassivePlugin.java index b94dacf4..22392435 100644 --- a/src/com/massivecraft/massivecore/MassivePlugin.java +++ b/src/com/massivecraft/massivecore/MassivePlugin.java @@ -352,30 +352,25 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name public List> getClassesActiveNms() { - return getClassesActive("nms", Mixin.class, new Predicate>() + return getClassesActive("nms", Mixin.class, (Predicate>) clazz -> { + try { - @Override - public boolean test(Class clazz) - { - try - { - ReflectionUtil.getField(clazz, "d"); - return true; - } - catch (Throwable throwable) - { - // We need to catch throwable here. - // NoClassDefFoundError will happen for NmsMixins targeting incompatible versions. - // On Minecraft 1.8 we did for example get this error: - // > java.lang.NoClassDefFoundError: org/bukkit/scoreboard/Team$Option - // > at java.lang.Class.getDeclaredFields0(Native Method) ~[?:1.8.0_111] - // > at java.lang.Class.privateGetDeclaredFields(Class.java:2583) ~[?:1.8.0_111] - // > at java.lang.Class.getDeclaredField(Class.java:2068) ~[?:1.8.0_111] - // The Java reflection itself is simply not careful enough. - return false; - } - } + ReflectionUtil.getField(clazz, "d"); + return true; } + catch (Throwable throwable) + { + // We need to catch throwable here. + // NoClassDefFoundError will happen for NmsMixins targeting incompatible versions. + // On Minecraft 1.8 we did for example get this error: + // > java.lang.NoClassDefFoundError: org/bukkit/scoreboard/Team$Option + // > at java.lang.Class.getDeclaredFields0(Native Method) ~[?:1.8.0_111] + // > at java.lang.Class.privateGetDeclaredFields(Class.java:2583) ~[?:1.8.0_111] + // > at java.lang.Class.getDeclaredField(Class.java:2068) ~[?:1.8.0_111] + // The Java reflection itself is simply not careful enough. + return false; + } + } ); } diff --git a/src/com/massivecraft/massivecore/Metrics.java b/src/com/massivecraft/massivecore/Metrics.java index 85686d30..62c9bd51 100644 --- a/src/com/massivecraft/massivecore/Metrics.java +++ b/src/com/massivecraft/massivecore/Metrics.java @@ -276,20 +276,17 @@ public class Metrics { data.put("plugins", pluginData); // Create a new thread for the connection to the bStats server - new Thread(new Runnable() { - @Override - public void run() { - try { - // Send the data - sendData(plugin, data); - } catch (Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); - } - } - } - }).start(); + new Thread(() -> { + try { + // Send the data + sendData(plugin, data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); + } + } + }).start(); } /** diff --git a/src/com/massivecraft/massivecore/PriorityLines.java b/src/com/massivecraft/massivecore/PriorityLines.java index 26b9b564..513b3423 100644 --- a/src/com/massivecraft/massivecore/PriorityLines.java +++ b/src/com/massivecraft/massivecore/PriorityLines.java @@ -36,7 +36,8 @@ public class PriorityLines implements Prioritized, Comparable this.lines = msonLines; } - public void setLine(Object line) { this.setLines(line); }; + public void setLine(Object line) { this.setLines(line); } + public List getLinesMson() { return new MassiveList<>(this.lines); } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/adapter/AdapterBackstringSet.java b/src/com/massivecraft/massivecore/adapter/AdapterBackstringSet.java index df2040cb..cc07168c 100644 --- a/src/com/massivecraft/massivecore/adapter/AdapterBackstringSet.java +++ b/src/com/massivecraft/massivecore/adapter/AdapterBackstringSet.java @@ -39,7 +39,7 @@ public class AdapterBackstringSet implements JsonDeserializer>, return context.serialize(src.getStringSet(), stringSetType); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "unchecked"}) @Override public BackstringSet deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { diff --git a/src/com/massivecraft/massivecore/adapter/AdapterMassiveX.java b/src/com/massivecraft/massivecore/adapter/AdapterMassiveX.java index d944374e..f684d749 100644 --- a/src/com/massivecraft/massivecore/adapter/AdapterMassiveX.java +++ b/src/com/massivecraft/massivecore/adapter/AdapterMassiveX.java @@ -171,7 +171,7 @@ public abstract class AdapterMassiveX implements JsonDeserializer, JsonSer Class clazz = (Class) actualTypeArguments[index]; try { - return clazz.newInstance(); + return clazz.getDeclaredConstructor().newInstance(); } catch (Exception e) { diff --git a/src/com/massivecraft/massivecore/adapter/AdapterModdedEnumType.java b/src/com/massivecraft/massivecore/adapter/AdapterModdedEnumType.java index 48c2da06..20aaa789 100644 --- a/src/com/massivecraft/massivecore/adapter/AdapterModdedEnumType.java +++ b/src/com/massivecraft/massivecore/adapter/AdapterModdedEnumType.java @@ -73,7 +73,7 @@ public final class AdapterModdedEnumType> extends TypeAdapter< public static TypeAdapterFactory newEnumTypeHierarchyFactory() { return new TypeAdapterFactory() { - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings({"unchecked"}) public TypeAdapter create(Gson gson, TypeToken typeToken) { Class rawType = typeToken.getRawType(); if (!Enum.class.isAssignableFrom(rawType) || rawType == Enum.class) { diff --git a/src/com/massivecraft/massivecore/adapter/AdapterPolymorphic.java b/src/com/massivecraft/massivecore/adapter/AdapterPolymorphic.java index 076f2ba6..6e2a073f 100644 --- a/src/com/massivecraft/massivecore/adapter/AdapterPolymorphic.java +++ b/src/com/massivecraft/massivecore/adapter/AdapterPolymorphic.java @@ -6,7 +6,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; @@ -56,7 +55,7 @@ public class AdapterPolymorphic implements JsonDeserializer, JsonSerialize throw new JsonParseException("A polymorph must be have a \"+VALUE+\" field."); } - String type = ((JsonPrimitive)jsonObject.get(TYPE)).getAsString(); + String type = jsonObject.get(TYPE).getAsString(); Class typeClass = null; try diff --git a/src/com/massivecraft/massivecore/chestgui/ChestActionAbstract.java b/src/com/massivecraft/massivecore/chestgui/ChestActionAbstract.java index 0fde511d..44efc329 100644 --- a/src/com/massivecraft/massivecore/chestgui/ChestActionAbstract.java +++ b/src/com/massivecraft/massivecore/chestgui/ChestActionAbstract.java @@ -4,6 +4,8 @@ import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.MUtil; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; public class ChestActionAbstract implements ChestAction { @@ -16,7 +18,28 @@ public class ChestActionAbstract implements ChestAction { Player player = IdUtil.getAsPlayer(event.getWhoClicked()); if (MUtil.isntPlayer(player)) return false; - + + // Variables + Inventory inventory = event.getInventory(); + ChestGui gui = ChestGui.get(inventory); + int slot = event.getSlot(); + + // Transform item + ItemStack itemBefore = event.getCurrentItem(); + ItemStack itemAfter = transformItem(itemBefore); + + if (itemAfter != null) + { + inventory.setItem(slot, itemAfter); + } + + // Transform action + ChestAction actionAfter = transformAction(); + if (actionAfter != null) + { + gui.setAction(slot, actionAfter); + } + return onClick(event, player); } @@ -24,5 +47,15 @@ public class ChestActionAbstract implements ChestAction { return false; } + + public ItemStack transformItem(ItemStack clickedItem) + { + return null; + } + + public ChestAction transformAction() + { + return null; + } } diff --git a/src/com/massivecraft/massivecore/chestgui/ChestActionToggle.java b/src/com/massivecraft/massivecore/chestgui/ChestActionToggle.java new file mode 100644 index 00000000..f24bb4eb --- /dev/null +++ b/src/com/massivecraft/massivecore/chestgui/ChestActionToggle.java @@ -0,0 +1,84 @@ +package com.massivecraft.massivecore.chestgui; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; + +public class ChestActionToggle extends ChestActionAbstract implements ChestButton +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final ItemStack enabledItem; + public ItemStack getEnabledItem() { return this.enabledItem; } + + private final ItemStack disabledItem; + public ItemStack getDisabledItem() { return this.disabledItem; } + + private final ChestAction enableAction; + public ChestAction getEnableAction() { return this.enableAction; } + + private final ChestAction disableAction; + public ChestAction getDisableAction() { return this.disableAction; } + + private boolean enabled; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ChestActionToggle(ItemStack enabledItem, ItemStack disabledItem, ChestAction enableAction, ChestAction disableAction, boolean enabled) + { + this.enabledItem = enabledItem; + this.disabledItem = disabledItem; + this.enableAction = enableAction; + this.disableAction = disableAction; + + this.enabled = enabled; + } + + // -------------------------------------------- // + // OVERRIDE: CHEST ACTION + // -------------------------------------------- // + + @Override + public boolean onClick(InventoryClickEvent event, Player player) + { + // If it is enabled then use the disable action + // If it is disabled use the enable action + boolean ret; + ChestAction inner = this.enabled ? this.getDisableAction() : this.getEnableAction(); + ret = inner.onClick(event); + + this.enabled = !this.enabled; + + return ret; + } + + // This method is run /before/ onClick + // so this.enabled has not yet changed value + @Override + public ItemStack transformItem(ItemStack clickedItem) + { + // Currently enabled means it will be disabled, so show the disable item and vice versa + return this.enabled ? this.getDisabledItem() : this.getEnabledItem(); + } + + // -------------------------------------------- // + // OVERRIDE: CHEST BUTTON + // -------------------------------------------- // + + @Override + public ChestAction getAction() + { + return this; + } + + @Override + public ItemStack getItem() + { + return this.enabled ? this.getEnabledItem() : this.getDisabledItem(); + } + +} diff --git a/src/com/massivecraft/massivecore/chestgui/ChestButton.java b/src/com/massivecraft/massivecore/chestgui/ChestButton.java new file mode 100644 index 00000000..e242fe4a --- /dev/null +++ b/src/com/massivecraft/massivecore/chestgui/ChestButton.java @@ -0,0 +1,10 @@ +package com.massivecraft.massivecore.chestgui; + +import org.bukkit.inventory.ItemStack; + +// This class is just used to construct ChestGui's +public interface ChestButton +{ + ChestAction getAction(); + ItemStack getItem(); +} diff --git a/src/com/massivecraft/massivecore/chestgui/ChestButtonSimple.java b/src/com/massivecraft/massivecore/chestgui/ChestButtonSimple.java new file mode 100644 index 00000000..7971f0e9 --- /dev/null +++ b/src/com/massivecraft/massivecore/chestgui/ChestButtonSimple.java @@ -0,0 +1,27 @@ +package com.massivecraft.massivecore.chestgui; + +import org.bukkit.inventory.ItemStack; + +public class ChestButtonSimple implements ChestButton +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final ChestAction action; + @Override public ChestAction getAction() { return this.action; } + + private final ItemStack item; + @Override public ItemStack getItem() { return this.item; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ChestButtonSimple(ChestAction action, ItemStack item) + { + this.action = action; + this.item = item; + } + +} diff --git a/src/com/massivecraft/massivecore/chestgui/ChestGui.java b/src/com/massivecraft/massivecore/chestgui/ChestGui.java index 3b1c8934..afe028f5 100644 --- a/src/com/massivecraft/massivecore/chestgui/ChestGui.java +++ b/src/com/massivecraft/massivecore/chestgui/ChestGui.java @@ -1,11 +1,13 @@ package com.massivecraft.massivecore.chestgui; -import com.massivecraft.massivecore.entity.MassiveCoreMConf; import com.massivecraft.massivecore.SoundEffect; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.entity.MassiveCoreMConf; +import org.bukkit.Bukkit; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; import java.util.List; import java.util.Map; @@ -33,6 +35,14 @@ public class ChestGui return gui; } + public static ChestGui get(InventoryEvent event) + { + if (event == null) throw new NullPointerException("event"); + + Inventory inventory = event.getInventory(); + if (inventory == null) return null; + return get(inventory); + } private static void add(Inventory inventory, ChestGui gui) { inventoryToGui.put(inventory, gui); } private static void remove(Inventory inventory) { inventoryToGui.remove(inventory); } @@ -73,10 +83,10 @@ public class ChestGui private Map indexToAction = new MassiveMap<>(); public Map getIndexToAction() { return this.indexToAction; } - public ChestAction removeAction(ItemStack item) { return this.indexToAction.remove(item); } public ChestAction setAction(int index, ChestAction action) { return this.indexToAction.put(index, action); } public ChestAction setAction(int index, String command) { return this.setAction(index, new ChestActionCommand(command)); } public ChestAction getAction(int index) { return this.indexToAction.get(index); } + public ChestAction getAction(InventoryClickEvent event) { return this.getAction(event.getSlot()); } // -------------------------------------------- // // LAST ACTION @@ -166,5 +176,28 @@ public class ChestGui { } + + public ChestGui constructFromButtons(List buttons) + { + int size = buttons.size(); + int modulo = size % 9; + if (modulo != 0) + { + size = size + 9 - modulo; + } + + Inventory inventory = Bukkit.createInventory(null, size); + ChestGui gui = getCreative(inventory); + + for (int i = 0; i < buttons.size(); i++) + { + ChestButton button = buttons.get(i); + + inventory.setItem(i, button.getItem()); + gui.setAction(i, button.getAction()); + } + + return gui; + } } diff --git a/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreCmdurl.java b/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreCmdurl.java index c15de53c..eb5e209c 100755 --- a/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreCmdurl.java +++ b/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreCmdurl.java @@ -60,52 +60,35 @@ public class CmdMassiveCoreCmdurl extends MassiveCoreCommand // Apply final Player commander = me; msg("Loading %s ...", urlString); - async(new Runnable() - { - @Override - public void run() + async(() -> { + try { - try - { - final List lines = WebUtil.getLines(url); - sync(new Runnable() + final List lines = WebUtil.getLines(url); + sync(() -> { + MixinMessage.get().msgOne(commander, "... %d lines loaded. Now executing ...", lines.size()); + for (int i = 0; i <= lines.size() - 1; i++) { - @Override - public void run() + String line = lines.get(i); + line = line.trim(); + if (line.length() == 0 || line.startsWith("#")) { - MixinMessage.get().msgOne(commander, "... %d lines loaded. Now executing ...", lines.size()); - for (int i = 0; i <= lines.size() - 1; i++) - { - String line = lines.get(i); - line = line.trim(); - if (line.length() == 0 || line.startsWith("#")) - { - MixinMessage.get().msgOne(commander, "#%d: %s", i, line); - // Ignore the line - } - else - { - MixinMessage.get().msgOne(commander, "#%d: %s", i, line); - // Run the line - commander.chat(line); - } - } + MixinMessage.get().msgOne(commander, "#%d: %s", i, line); + // Ignore the line } - }); - return; - } - catch (final Exception e) - { - sync(new Runnable() - { - @Override - public void run() + else { - MixinMessage.get().msgOne(commander, "%s: %s", e.getClass().getSimpleName(), e.getMessage()); + MixinMessage.get().msgOne(commander, "#%d: %s", i, line); + // Run the line + commander.chat(line); } - }); - return; - } + } + }); + return; + } + catch (final Exception e) + { + sync(() -> MixinMessage.get().msgOne(commander, "%s: %s", e.getClass().getSimpleName(), e.getMessage())); + return; } }); } diff --git a/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreUsysMultiverseList.java b/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreUsysMultiverseList.java index 4a1b6f7f..9fae67b9 100755 --- a/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreUsysMultiverseList.java +++ b/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreUsysMultiverseList.java @@ -31,14 +31,7 @@ public class CmdMassiveCoreUsysMultiverseList extends MassiveCoreCommand int page = this.readArg(); // Pager Create - Pager pager = new Pager<>(this, "Multiverse List", page, MultiverseColl.get().getAll(), new Stringifier() - { - @Override - public String toString(Multiverse multiverse, int index) - { - return Txt.parse("" + multiverse.getId() + " has " + Txt.implodeCommaAndDot(multiverse.getUniverses(), "%s", ", ", " and ", ".")); - } - }); + Pager pager = new Pager<>(this, "Multiverse List", page, MultiverseColl.get().getAll(), (Stringifier) (multiverse, index) -> Txt.parse("" + multiverse.getId() + " has " + Txt.implodeCommaAndDot(multiverse.getUniverses(), "%s", ", ", " and ", "."))); // Pager Message pager.message(); diff --git a/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreUsysWorld.java b/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreUsysWorld.java index fbef72e1..e48a03c3 100755 --- a/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreUsysWorld.java +++ b/src/com/massivecraft/massivecore/cmd/CmdMassiveCoreUsysWorld.java @@ -28,7 +28,7 @@ public class CmdMassiveCoreUsysWorld extends MassiveCoreCommand { String worldName = this.readArg(); String universe = this.readArg(); - Multiverse multiverse = (Multiverse) this.readArg(); + Multiverse multiverse = this.readArg(); if (!multiverse.containsUniverse(universe)) { diff --git a/src/com/massivecraft/massivecore/command/MassiveCommand.java b/src/com/massivecraft/massivecore/command/MassiveCommand.java index 5ceef3e8..e91d3723 100644 --- a/src/com/massivecraft/massivecore/command/MassiveCommand.java +++ b/src/com/massivecraft/massivecore/command/MassiveCommand.java @@ -983,7 +983,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand { if (this instanceof MassiveCommandDeprecated) return; - for (Field field : this.getClassOrEnclosing(this).getDeclaredFields()) + for (Field field : getClassOrEnclosing(this).getDeclaredFields()) { ReflectionUtil.makeAccessible(field); Class fieldType = field.getType(); diff --git a/src/com/massivecraft/massivecore/command/MassiveCommandSetSharding.java b/src/com/massivecraft/massivecore/command/MassiveCommandSetSharding.java index d4f4d48c..ab16e7f2 100644 --- a/src/com/massivecraft/massivecore/command/MassiveCommandSetSharding.java +++ b/src/com/massivecraft/massivecore/command/MassiveCommandSetSharding.java @@ -77,7 +77,7 @@ public abstract class MassiveCommandSetSharding extends if (!PermissionUtil.hasPermission(sender, this.getPermSetOther(), true)) return; } - EventMassiveCoreCommandSet event = new EventMassiveCoreCommandSet(senderId, targetId, after, this.getPlayerValue(), this.getName()); + EventMassiveCoreCommandSet event = new EventMassiveCoreCommandSet<>(senderId, targetId, after, this.getPlayerValue(), this.getName()); MixinEvent.get().distribute(event, true); } diff --git a/src/com/massivecraft/massivecore/command/MassiveCoreBukkitCommand.java b/src/com/massivecraft/massivecore/command/MassiveCoreBukkitCommand.java index 2bb7c3ce..ff4625d5 100644 --- a/src/com/massivecraft/massivecore/command/MassiveCoreBukkitCommand.java +++ b/src/com/massivecraft/massivecore/command/MassiveCoreBukkitCommand.java @@ -34,7 +34,7 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia name, massiveCommand.getDesc(), massiveCommand.getTemplate().toPlain(true), - Collections.emptyList() // We don't use aliases + Collections.emptyList() // We don't use aliases ); this.massiveCommand = massiveCommand; } diff --git a/src/com/massivecraft/massivecore/command/type/RegistryType.java b/src/com/massivecraft/massivecore/command/type/RegistryType.java index 20850e19..195f2e31 100644 --- a/src/com/massivecraft/massivecore/command/type/RegistryType.java +++ b/src/com/massivecraft/massivecore/command/type/RegistryType.java @@ -29,11 +29,10 @@ import com.massivecraft.massivecore.command.type.enumeration.TypeHorseStyle; import com.massivecraft.massivecore.command.type.enumeration.TypeHorseVariant; import com.massivecraft.massivecore.command.type.enumeration.TypeLlamaColor; import com.massivecraft.massivecore.command.type.enumeration.TypeMaterial; -import com.massivecraft.massivecore.command.type.enumeration.TypeOcelotType; +import com.massivecraft.massivecore.command.type.enumeration.TypeCatType; import com.massivecraft.massivecore.command.type.enumeration.TypeParrotVariant; import com.massivecraft.massivecore.command.type.enumeration.TypeParticle; import com.massivecraft.massivecore.command.type.enumeration.TypeRabbitType; -import com.massivecraft.massivecore.command.type.enumeration.TypeSkeletonType; import com.massivecraft.massivecore.command.type.enumeration.TypeSound; import com.massivecraft.massivecore.command.type.enumeration.TypeSpawnReason; import com.massivecraft.massivecore.command.type.enumeration.TypeVillagerProfession; @@ -309,14 +308,13 @@ public class RegistryType register(TypeHorseStyle.get()); register(TypeHorseVariant.get()); register(TypeMaterial.get()); - register(TypeOcelotType.get()); + register(TypeCatType.get()); register(TypeParticle.get()); register(TypeSpawnReason.get()); register(TypeRabbitType.get()); register(TypeDamageModifier.get()); register(TypeLlamaColor.get()); register(TypeParrotVariant.get()); - register(TypeSkeletonType.get()); register(TypeSound.get()); register(TypeVillagerProfession.get()); register(TypeWorldType.get()); diff --git a/src/com/massivecraft/massivecore/command/type/TypeAbstract.java b/src/com/massivecraft/massivecore/command/type/TypeAbstract.java index 8411b7d4..f19acd09 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeAbstract.java +++ b/src/com/massivecraft/massivecore/command/type/TypeAbstract.java @@ -29,7 +29,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.ListIterator; import java.util.Set; public abstract class TypeAbstract implements Type @@ -106,7 +105,7 @@ public abstract class TypeAbstract implements Type @Override public > I getInnerType(int index) { return (I) this.getInnerTypes().get(index); } @Override public > I getInnerType() { return this.getInnerType(0); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "unchecked"}) @Override public void setInnerTypes(Collection> innerTypes) { this.innerTypes = new MassiveList(innerTypes); } @Override public void setInnerTypes(Type... innerTypes) { this.setInnerTypes(Arrays.asList(innerTypes)); } @@ -151,7 +150,7 @@ public abstract class TypeAbstract implements Type @SuppressWarnings("unchecked") public > I getInnerProperty(int index) { return (I) this.getInnerProperties().get(index); } - public > void setInnerProperties(Collection innerProperties) { this.innerProperties = new MassiveList>(innerProperties); } + public > void setInnerProperties(Collection innerProperties) { this.innerProperties = new MassiveList<>(innerProperties); } @SafeVarargs public final > void setInnerProperties(I... innerProperties) { this.setInnerProperties(Arrays.asList(innerProperties)); } public void setInnerProperties(Class clazz) { this.setInnerProperties(PropertyReflection.getAll(clazz, this)); } @@ -436,15 +435,7 @@ public abstract class TypeAbstract implements Type // Currently we just throw away nulls and empty strings. private static void cleanSuggestions(List suggestions) { - ListIterator iter = suggestions.listIterator(); - while (iter.hasNext()) - { - String suggestion = iter.next(); - if (suggestion == null || suggestion.isEmpty()) - { - iter.remove(); - } - } + suggestions.removeIf(suggestion -> suggestion == null || suggestion.isEmpty()); } public static List prepareForSpaces(List suggestions, String arg) diff --git a/src/com/massivecraft/massivecore/command/type/TypeEnchantment.java b/src/com/massivecraft/massivecore/command/type/TypeEnchantment.java index cc2a372b..c07b7570 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeEnchantment.java +++ b/src/com/massivecraft/massivecore/command/type/TypeEnchantment.java @@ -18,7 +18,7 @@ public class TypeEnchantment extends TypeAbstractChoice // The first name is taken from the wiki. Those names are those people think of. // The second name is the Bukkit enum name. // Thereafter comes assorted extras - public static Map> ID_TO_RAWNAMES = new MassiveMap>( + public static Map> ID_TO_RAWNAMES = new MassiveMap<>( 0, new MassiveList<>("Protection", "PROTECTION_ENVIRONMENTAL"), 1, new MassiveList<>("Fire Protection", "PROTECTION_FIRE"), 2, new MassiveList<>("Feather Falling", "PROTECTION_FALL", "FallProtection"), diff --git a/src/com/massivecraft/massivecore/command/type/TypePS.java b/src/com/massivecraft/massivecore/command/type/TypePS.java index e1cdfd47..4cdeaa3e 100644 --- a/src/com/massivecraft/massivecore/command/type/TypePS.java +++ b/src/com/massivecraft/massivecore/command/type/TypePS.java @@ -61,7 +61,7 @@ public class TypePS extends TypeAbstract } // We remove all commas optionally followed by spaces - String argInner = arg.replaceAll("\\:\\s*", ""); + String argInner = arg.replaceAll(":\\s*", ""); // We split on comma and space to get the list of raw entries. List parts = Arrays.asList(argInner.split("[\\s,]+")); diff --git a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java index cc8ae2d6..8eedbaa1 100644 --- a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java +++ b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java @@ -163,7 +163,7 @@ public abstract class TypeCombined extends TypeAbstract { Type type = this.getInnerType(i); Object part = parts.get(i); - SimpleEntry, Object> entry = new SimpleEntry, Object>(type, part); + SimpleEntry, Object> entry = new SimpleEntry<>(type, part); ret.add(entry); } diff --git a/src/com/massivecraft/massivecore/command/type/container/TypeContainer.java b/src/com/massivecraft/massivecore/command/type/container/TypeContainer.java index 4d131fd8..bf5f534a 100644 --- a/src/com/massivecraft/massivecore/command/type/container/TypeContainer.java +++ b/src/com/massivecraft/massivecore/command/type/container/TypeContainer.java @@ -190,7 +190,7 @@ public abstract class TypeContainer extends TypeAbstract // Check All if (this.getInnerType() instanceof AllAble) { - AllAble allAble = (AllAble)this.getInnerType(); + AllAble allAble = this.getInnerType(); if (arg.equalsIgnoreCase("all")) { ContainerUtil.addElements(ret, allAble.getAll(sender)); diff --git a/src/com/massivecraft/massivecore/command/type/enumeration/TypeOcelotType.java b/src/com/massivecraft/massivecore/command/type/enumeration/TypeCatType.java similarity index 50% rename from src/com/massivecraft/massivecore/command/type/enumeration/TypeOcelotType.java rename to src/com/massivecraft/massivecore/command/type/enumeration/TypeCatType.java index 8377859d..4b5ec17c 100644 --- a/src/com/massivecraft/massivecore/command/type/enumeration/TypeOcelotType.java +++ b/src/com/massivecraft/massivecore/command/type/enumeration/TypeCatType.java @@ -1,16 +1,16 @@ package com.massivecraft.massivecore.command.type.enumeration; -import org.bukkit.entity.Ocelot.Type; +import org.bukkit.entity.Cat.Type; -public class TypeOcelotType extends TypeEnum +public class TypeCatType extends TypeEnum { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static TypeOcelotType i = new TypeOcelotType(); - public static TypeOcelotType get() { return i; } - public TypeOcelotType() + private static TypeCatType i = new TypeCatType(); + public static TypeCatType get() { return i; } + public TypeCatType() { super(Type.class); } diff --git a/src/com/massivecraft/massivecore/command/type/enumeration/TypeSkeletonType.java b/src/com/massivecraft/massivecore/command/type/enumeration/TypeSkeletonType.java deleted file mode 100644 index 341e83ed..00000000 --- a/src/com/massivecraft/massivecore/command/type/enumeration/TypeSkeletonType.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.massivecraft.massivecore.command.type.enumeration; - -import org.bukkit.entity.Skeleton.SkeletonType; - -public class TypeSkeletonType extends TypeEnum -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeSkeletonType i = new TypeSkeletonType(); - public static TypeSkeletonType get() { return i; } - public TypeSkeletonType() - { - super(SkeletonType.class); - } - -} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorCollection.java b/src/com/massivecraft/massivecore/comparator/ComparatorCollection.java index 9db5dd95..96a6873e 100644 --- a/src/com/massivecraft/massivecore/comparator/ComparatorCollection.java +++ b/src/com/massivecraft/massivecore/comparator/ComparatorCollection.java @@ -3,7 +3,6 @@ package com.massivecraft.massivecore.comparator; import com.massivecraft.massivecore.collections.MassiveList; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -44,10 +43,10 @@ public class ComparatorCollection extends ComparatorAbstract // Elements List elements1 = new MassiveList<>(collection1); - Collections.sort(elements1, ComparatorSmart.get()); + elements1.sort(ComparatorSmart.get()); List elements2 = new MassiveList<>(collection2); - Collections.sort(elements2, ComparatorSmart.get()); + elements2.sort(ComparatorSmart.get()); Iterator iterator1 = elements1.iterator(); Iterator iterator2 = elements2.iterator(); diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreChestGui.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreChestGui.java index e1469459..cc9d365f 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreChestGui.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreChestGui.java @@ -15,7 +15,6 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; public class EngineMassiveCoreChestGui extends Engine { @@ -33,12 +32,8 @@ public class EngineMassiveCoreChestGui extends Engine @EventHandler(priority = EventPriority.LOW) public void onClick(InventoryClickEvent event) { - // If this inventory ... - Inventory inventory = event.getInventory(); - if (inventory == null) return; - - // ... is a gui ... - ChestGui gui = ChestGui.get(inventory); + // If this inventory is a gui ... + ChestGui gui = ChestGui.get(event); if (gui == null) return; // ... then cancel the event ... @@ -61,12 +56,9 @@ public class EngineMassiveCoreChestGui extends Engine return; } - - // ... and if this slot index ... - int index = event.getSlot(); - - // ... has an action ... - ChestAction action = gui.getAction(index); + + // ... and if this slot index has an action ... + ChestAction action = gui.getAction(event); if (action == null) return; // ... set last action ... @@ -87,9 +79,7 @@ public class EngineMassiveCoreChestGui extends Engine public void onOpen(InventoryOpenEvent event) { // Get - final Inventory inventory = event.getInventory(); - if (inventory == null) return; - final ChestGui gui = ChestGui.get(inventory); + final ChestGui gui = ChestGui.get(event); if (gui == null) return; // Sound @@ -101,17 +91,9 @@ public class EngineMassiveCoreChestGui extends Engine } // Later - Bukkit.getScheduler().runTask(getPlugin(), new Runnable() - { - @Override - public void run() - { - // Runnables - for (Runnable runnable : gui.getRunnablesOpen()) - { - runnable.run(); - } - } + Bukkit.getScheduler().runTask(getPlugin(), () -> { + // Runnables + gui.getRunnablesOpen().forEach(Runnable::run); }); } @@ -119,32 +101,22 @@ public class EngineMassiveCoreChestGui extends Engine public void onClose(InventoryCloseEvent event) { // Get - final Inventory inventory = event.getInventory(); - if (inventory == null) return; - final ChestGui gui = ChestGui.get(inventory); + final ChestGui gui = ChestGui.get(event); if (gui == null) return; // Human final HumanEntity human = event.getPlayer(); // Later - Bukkit.getScheduler().runTask(getPlugin(), new Runnable() - { - @Override - public void run() + Bukkit.getScheduler().runTask(getPlugin(), () -> { + // Runnables + gui.getRunnablesClose().forEach(Runnable::run); + + // Sound + SoundEffect sound = gui.getSoundClose(); + if (sound != null && human.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) { - // Runnables - for (Runnable runnable : gui.getRunnablesClose()) - { - runnable.run(); - } - - // Sound - SoundEffect sound = gui.getSoundClose(); - if (sound != null && human.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) - { - sound.run(human); - } + sound.run(human); } }); @@ -152,14 +124,7 @@ public class EngineMassiveCoreChestGui extends Engine { // We save the inventory in the map for a little while. // A plugin may want to do something upon the chest gui closing. - Bukkit.getScheduler().runTaskLater(this.getPlugin(), new Runnable() - { - @Override - public void run() - { - gui.remove(); - } - }, 20); + Bukkit.getScheduler().runTaskLater(this.getPlugin(), gui::remove, 20); } } diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreClean.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreClean.java index 96a4f5c0..379caa29 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreClean.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreClean.java @@ -59,7 +59,7 @@ public class EngineMassiveCoreClean extends Engine MassiveCoreMConf.get().cleanTaskLastMillis = now; MassiveCoreMConf.get().changed(); - List recipients = Collections.singletonList(IdUtil.getConsole()); + List recipients = Collections.singletonList(IdUtil.getConsole()); for (Coll coll : Coll.getInstances()) { if (!coll.isCleanTaskEnabled()) continue; diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreCommandRegistration.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreCommandRegistration.java index a1b5dcdd..fc8c34b7 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreCommandRegistration.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreCommandRegistration.java @@ -13,7 +13,6 @@ import org.bukkit.plugin.Plugin; import java.lang.reflect.Field; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -91,20 +90,18 @@ public class EngineMassiveCoreCommandRegistration extends Engine List> deregisters = new MassiveList<>(); - Iterator> iter = knownCommands.entrySet().iterator(); - while (iter.hasNext()) + for (Entry entry : knownCommands.entrySet()) { - Entry entry = iter.next(); String name = entry.getKey(); Command command = entry.getValue(); - + // ... that is a MassiveCoreBukkitCommand ... MassiveCommand massiveCommand = getMassiveCommand(command); if (massiveCommand == null) continue; - + // ... and not a target ... if (nameTargets.containsKey(name)) continue; - + // ... unregister it. deregisters.add(entry); } diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreDatabase.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreDatabase.java index ee6002e9..bd50ae59 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreDatabase.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreDatabase.java @@ -71,14 +71,7 @@ public class EngineMassiveCoreDatabase extends Engine // Same as above but next tick. public static void setSenderReferencesSoon(final CommandSender sender, final CommandSender reference, final PlayerLoginEvent event) { - Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - setSenderReferences(sender, reference, event); - } - }); + Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), () -> setSenderReferences(sender, reference, event)); } @EventHandler(priority = EventPriority.LOWEST) @@ -143,14 +136,7 @@ public class EngineMassiveCoreDatabase extends Engine // Without this we might cause a memory leak. // Players might trigger AsyncPlayerPreLoginEvent but not PlayerLoginEvent. // Using WeakHashMap is not an option since the player object does not exist at AsyncPlayerPreLoginEvent. - Bukkit.getScheduler().runTaskLaterAsynchronously(this.getPlugin(), new Runnable() - { - @Override - public void run() - { - idToRemoteEntries.remove(playerId); - } - }, 20*30); + Bukkit.getScheduler().runTaskLaterAsynchronously(this.getPlugin(), () -> idToRemoteEntries.remove(playerId), 20*30); } // Intended to be ran synchronously. diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreDestination.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreDestination.java index 7dc8094d..0a6297aa 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreDestination.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreDestination.java @@ -93,7 +93,7 @@ public class EngineMassiveCoreDestination extends Engine // Prepare arg = arg.toLowerCase(); - List parts = Arrays.asList(arg.split("[\\s\\,\\:]+", 2)); + List parts = Arrays.asList(arg.split("[\\s,:]+", 2)); String first = parts.get(0); String rest = null; if (parts.size() > 1) rest = parts.get(1); diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java index b9c184f7..ea622ddf 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java @@ -201,14 +201,7 @@ public class EngineMassiveCoreMain extends Engine final UUID uuid = player.getUniqueId(); // We do the schedule in order for the set to be correct through out the whole MONITOR priority state. - Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - kickedPlayerReasons.remove(uuid); - } - }); + Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), () -> kickedPlayerReasons.remove(uuid)); } } diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCorePlayerLeave.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCorePlayerLeave.java index be84e9d7..b6777d8e 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCorePlayerLeave.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCorePlayerLeave.java @@ -57,14 +57,7 @@ public class EngineMassiveCorePlayerLeave extends Engine new EventMassiveCorePlayerLeave(player, false, "quit", null).run(); // We do the schedule in order for the set to be correct through out the whole MONITOR priority state. - Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - EventMassiveCorePlayerLeave.player2event.remove(uuid); - } - }); + Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), () -> EventMassiveCorePlayerLeave.player2event.remove(uuid)); } } diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCorePlayerState.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCorePlayerState.java index e1d185b5..4157f393 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCorePlayerState.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCorePlayerState.java @@ -76,14 +76,7 @@ public class EngineMassiveCorePlayerState extends Engine // Delayed! if (delayed) { - Bukkit.getScheduler().runTask(this.getPlugin(), new Runnable() - { - @Override - public void run() - { - EngineMassiveCorePlayerState.this.setState(id, state, false, replaceable); - } - }); + Bukkit.getScheduler().runTask(this.getPlugin(), () -> EngineMassiveCorePlayerState.this.setState(id, state, false, replaceable)); return; } diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreTeleportMixinCause.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreTeleportMixinCause.java index dfadf86d..e8f38d1c 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreTeleportMixinCause.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreTeleportMixinCause.java @@ -28,7 +28,7 @@ public class EngineMassiveCoreTeleportMixinCause extends Engine public boolean isMixinCausedTeleportIncoming() { return this.mixinCausedTeleportIncoming; } public void setMixinCausedTeleportIncoming(boolean mixinCausedTeleportIncoming) { this.mixinCausedTeleportIncoming = mixinCausedTeleportIncoming; } - private Set mixinCausedTeleportEvents = Collections.newSetFromMap(new ConcurrentHashMap()); + private Set mixinCausedTeleportEvents = Collections.newSetFromMap(new ConcurrentHashMap<>()); // -------------------------------------------- // // TO BE USED @@ -49,14 +49,7 @@ public class EngineMassiveCoreTeleportMixinCause extends Engine if (!mixinCausedTeleportIncoming) return; mixinCausedTeleportIncoming = false; mixinCausedTeleportEvents.add(event); - Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - mixinCausedTeleportEvents.remove(event); - } - }); + Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), () -> mixinCausedTeleportEvents.remove(event)); } } diff --git a/src/com/massivecraft/massivecore/entity/Multiverse.java b/src/com/massivecraft/massivecore/entity/Multiverse.java index a7a100f9..b67f5091 100644 --- a/src/com/massivecraft/massivecore/entity/Multiverse.java +++ b/src/com/massivecraft/massivecore/entity/Multiverse.java @@ -68,8 +68,7 @@ public class Multiverse extends Entity public Set getUniverses() { - Set ret = new TreeSet<>(); - ret.addAll(this.uw.keySet()); + Set ret = new TreeSet<>(this.uw.keySet()); ret.add(MassiveCore.DEFAULT); return ret; } @@ -133,9 +132,8 @@ public class Multiverse extends Entity { Set orig = this.uw.get(universe); if (orig == null) return null; - - Set ret = new TreeSet<>(); - ret.addAll(orig); + + Set ret = new TreeSet<>(orig); return ret; } diff --git a/src/com/massivecraft/massivecore/fetcher/Fetcher.java b/src/com/massivecraft/massivecore/fetcher/Fetcher.java index c819444d..0c811549 100644 --- a/src/com/massivecraft/massivecore/fetcher/Fetcher.java +++ b/src/com/massivecraft/massivecore/fetcher/Fetcher.java @@ -78,23 +78,9 @@ public class Fetcher implements Callable> } // Create Tasks - Callable> taskName = new Callable>() - { - @Override - public Set call() throws Exception - { - return new HashSet<>(new FetcherByName(names).call().values()); - } - }; + Callable> taskName = () -> new HashSet<>(new FetcherByName(names).call().values()); - Callable> taskId = new Callable>() - { - @Override - public Set call() throws Exception - { - return new HashSet<>(new FetcherById(ids).call().values()); - } - }; + Callable> taskId = () -> new HashSet<>(new FetcherById(ids).call().values()); final List>> tasks = new ArrayList<>(); tasks.add(taskName); diff --git a/src/com/massivecraft/massivecore/mixin/MixinMessage.java b/src/com/massivecraft/massivecore/mixin/MixinMessage.java index 8f3c5b4f..8f1fc65f 100644 --- a/src/com/massivecraft/massivecore/mixin/MixinMessage.java +++ b/src/com/massivecraft/massivecore/mixin/MixinMessage.java @@ -2,7 +2,6 @@ package com.massivecraft.massivecore.mixin; import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.nms.NmsChat; -import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.Txt; import org.bukkit.command.CommandSender; @@ -10,6 +9,7 @@ import org.bukkit.command.CommandSender; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.function.Predicate; public class MixinMessage extends Mixin { @@ -134,7 +134,7 @@ public class MixinMessage extends Mixin // Here for (CommandSender sender : IdUtil.getLocalSenders()) { - if ( ! predicate.apply(sender)) continue; + if ( ! predicate.test(sender)) continue; this.messageOne(sender, messages); } diff --git a/src/com/massivecraft/massivecore/money/Money.java b/src/com/massivecraft/massivecore/money/Money.java index c1707c9c..dd8629b7 100644 --- a/src/com/massivecraft/massivecore/money/Money.java +++ b/src/com/massivecraft/massivecore/money/Money.java @@ -57,7 +57,7 @@ public class Money public static String format(double amount, boolean includeUnit) { - if (disabled()) return String.valueOf(amount) + (includeUnit ? "$": ""); + if (disabled()) return amount + (includeUnit ? "$": ""); return mixin.format(amount, includeUnit); } diff --git a/src/com/massivecraft/massivecore/money/MoneyMixinAbstract.java b/src/com/massivecraft/massivecore/money/MoneyMixinAbstract.java index 1b63481c..bf8afbcb 100644 --- a/src/com/massivecraft/massivecore/money/MoneyMixinAbstract.java +++ b/src/com/massivecraft/massivecore/money/MoneyMixinAbstract.java @@ -65,7 +65,7 @@ public abstract class MoneyMixinAbstract implements MoneyMixin } public boolean move(String fromId, String toId, String byId, double amount) { - return this.move(fromId, toId, byId, amount, Collections.emptyList(), null); + return this.move(fromId, toId, byId, amount, Collections.emptyList(), null); } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/mson/Mson.java b/src/com/massivecraft/massivecore/mson/Mson.java index d9c4b291..7c361885 100644 --- a/src/com/massivecraft/massivecore/mson/Mson.java +++ b/src/com/massivecraft/massivecore/mson/Mson.java @@ -972,15 +972,10 @@ public class Mson implements Serializable if (replacements == null) throw new NullPointerException("replacements"); final MutableInt i = new MutableInt(0); - MsonReplacement replacer = new MsonReplacement() - { - @Override - public Mson getReplacement(String match, Mson parent) - { - int idx = i.intValue(); - i.setValue(idx+1); - return replacements[idx % replacements.length]; - } + MsonReplacement replacer = (match, parent) -> { + int idx = i.intValue(); + i.setValue(idx+1); + return replacements[idx % replacements.length]; }; return this.replaceAll(pattern, replacer); } @@ -1021,7 +1016,7 @@ public class Mson implements Serializable if (addStringBuffer(msons, currentString)) currentString = new StringBuffer(); // Add this replacement - msons.add((Mson) replacement); + msons.add(replacement); } } diff --git a/src/com/massivecraft/massivecore/pager/Pager.java b/src/com/massivecraft/massivecore/pager/Pager.java index 2e808228..a808087b 100644 --- a/src/com/massivecraft/massivecore/pager/Pager.java +++ b/src/com/massivecraft/massivecore/pager/Pager.java @@ -98,13 +98,7 @@ public class Pager protected Msonifier msonifier = null; public boolean hasMsonifier() { return this.msonifier != null; } public Pager setMsonifier(Msonifier msonifier) { this.msonifier = msonifier; return this; } - public Pager setMsonifier(final Stringifier stringifier) { this.msonifier = new Msonifier(){ - @Override - public Mson toMson(T item, int index) - { - return Mson.fromParsedMessage(stringifier.toString(item, index)); - } - }; return this; } + public Pager setMsonifier(final Stringifier stringifier) { this.msonifier = (item, index) -> Mson.fromParsedMessage(stringifier.toString(item, index)); return this; } public Msonifier getMsonifier() { return this.msonifier; } // -------------------------------------------- // @@ -272,14 +266,7 @@ public class Pager public void messageAsync() { - Bukkit.getScheduler().runTaskAsynchronously(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - message(); - } - }); + Bukkit.getScheduler().runTaskAsynchronously(MassiveCore.get(), this::message); } } diff --git a/src/com/massivecraft/massivecore/ps/PS.java b/src/com/massivecraft/massivecore/ps/PS.java index fb52143a..fc461001 100644 --- a/src/com/massivecraft/massivecore/ps/PS.java +++ b/src/com/massivecraft/massivecore/ps/PS.java @@ -506,7 +506,7 @@ public final class PS implements Serializable, Comparable public static Integer calcBlockCoord(Double location, Integer block, Integer chunk) { if (block != null) return block; - if (location != null) return (int) Location.locToBlock(location); + if (location != null) return Location.locToBlock(location); if (chunk != null) return chunk * 16; return null; } diff --git a/src/com/massivecraft/massivecore/store/Coll.java b/src/com/massivecraft/massivecore/store/Coll.java index edc55c19..ca633f89 100644 --- a/src/com/massivecraft/massivecore/store/Coll.java +++ b/src/com/massivecraft/massivecore/store/Coll.java @@ -421,7 +421,7 @@ public class Coll> extends CollAbstract } boolean existsLocal = (localEntity != null); - boolean existsRemote = remote ? (remoteMtime != 0) : true; + boolean existsRemote = !remote || (remoteMtime != 0); // So we don't have this anywhere? if ( ! existsLocal && ! existsRemote) return Modification.UNKNOWN; @@ -828,7 +828,7 @@ public class Coll> extends CollAbstract // Id if (id == null) id = this.calculateId(); this.id = id; - String[] idParts = this.id.split("\\@"); + String[] idParts = this.id.split("@"); this.basename = idParts[0]; if (idParts.length > 1) { @@ -849,10 +849,7 @@ public class Coll> extends CollAbstract this.identifiedModifications = new ConcurrentHashMap<>(); // Tasks - this.tickTask = new Runnable() - { - @Override public void run() { Coll.this.onTick(); } - }; + this.tickTask = Coll.this::onTick; } public Coll(String id) diff --git a/src/com/massivecraft/massivecore/store/EntityContainerAbstract.java b/src/com/massivecraft/massivecore/store/EntityContainerAbstract.java index 88f16b66..6a284141 100644 --- a/src/com/massivecraft/massivecore/store/EntityContainerAbstract.java +++ b/src/com/massivecraft/massivecore/store/EntityContainerAbstract.java @@ -37,7 +37,7 @@ public abstract class EntityContainerAbstract> imple public String fixIdOrThrow(Object oid) throws IllegalArgumentException { String ret = this.fixId(oid); - if (ret == null) throw new IllegalArgumentException(String.valueOf(oid) + " is not a valid id."); + if (ret == null) throw new IllegalArgumentException(oid + " is not a valid id."); return ret; } diff --git a/src/com/massivecraft/massivecore/store/EntityInternalMap.java b/src/com/massivecraft/massivecore/store/EntityInternalMap.java index aa6e6b90..b6d23133 100644 --- a/src/com/massivecraft/massivecore/store/EntityInternalMap.java +++ b/src/com/massivecraft/massivecore/store/EntityInternalMap.java @@ -3,7 +3,6 @@ package com.massivecraft.massivecore.store; import com.massivecraft.massivecore.collections.MassiveSet; import java.lang.ref.WeakReference; -import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; @@ -40,7 +39,7 @@ public class EntityInternalMap> extends EntityContai // -------------------------------------------- // protected transient WeakReference> entity = new WeakReference<>(null); - protected void setEntity(EntityInternal entity) { this.entity = new WeakReference>(entity); } + protected void setEntity(EntityInternal entity) { this.entity = new WeakReference<>(entity); } public EntityInternal getEntity() { return this.entity.get(); } @Override @@ -113,14 +112,13 @@ public class EntityInternalMap> extends EntityContai Set> removals = new MassiveSet<>(); // Loop over all current entries ... - for (Iterator> it = this.id2Entity.entrySet().iterator(); it.hasNext(); ) + for (Entry entry : this.id2Entity.entrySet()) { - Entry entry = it.next(); String id = entry.getKey(); - + // ... if it is not present in those ... if (that.id2Entity.containsKey(id)) continue; - + // ... remove. removals.add(entry); } diff --git a/src/com/massivecraft/massivecore/store/GsonCloner.java b/src/com/massivecraft/massivecore/store/GsonCloner.java index a3457af4..4aa260d9 100644 --- a/src/com/massivecraft/massivecore/store/GsonCloner.java +++ b/src/com/massivecraft/massivecore/store/GsonCloner.java @@ -6,7 +6,6 @@ import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import java.util.Iterator; import java.util.Map.Entry; public class GsonCloner @@ -58,9 +57,9 @@ public class GsonCloner public static JsonArray cloneJsonArray(JsonArray array) { JsonArray ret = new JsonArray(); - for (Iterator iter = array.iterator(); iter.hasNext();) + for (JsonElement jsonElement : array) { - ret.add(clone(iter.next())); + ret.add(clone(jsonElement)); } return ret; } diff --git a/src/com/massivecraft/massivecore/store/GsonMongoConverter.java b/src/com/massivecraft/massivecore/store/GsonMongoConverter.java index 79d796b3..22e40f28 100644 --- a/src/com/massivecraft/massivecore/store/GsonMongoConverter.java +++ b/src/com/massivecraft/massivecore/store/GsonMongoConverter.java @@ -173,19 +173,16 @@ public final class GsonMongoConverter if (!(inObject instanceof BasicDBList)) throw new IllegalArgumentException("Expected BasicDBList as argument type!"); BasicDBList in = (BasicDBList)inObject; JsonArray jsonArray = new JsonArray(); - for (int i = 0; i < in.size(); i++) + for (Object object : in) { - Object object = in.get(i); if (object instanceof BasicDBList) { jsonArray.add(mongo2GsonArray((BasicDBList) object)); - } - else if (object instanceof BasicDBObject) + } else if (object instanceof BasicDBObject) { jsonArray.add(mongo2GsonObject((BasicDBObject) object)); - } - else - { + } else + { jsonArray.add(mongo2GsonPrimitive(object)); } } diff --git a/src/com/massivecraft/massivecore/store/SenderColl.java b/src/com/massivecraft/massivecore/store/SenderColl.java index 6d6723c5..e2efe8bb 100644 --- a/src/com/massivecraft/massivecore/store/SenderColl.java +++ b/src/com/massivecraft/massivecore/store/SenderColl.java @@ -148,23 +148,9 @@ public class SenderColl> extends Coll implements Se // GET ALL ONLINE / OFFLINE // -------------------------------------------- // - public static final Predicate> PREDICATE_ONLINE = new Predicate>() - { - @Override - public boolean apply(SenderEntity entity) - { - return entity.isOnline(); - } - }; + public static final Predicate> PREDICATE_ONLINE = SenderEntity::isOnline; - public static final Predicate> PREDICATE_OFFLINE = new Predicate>() - { - @Override - public boolean apply(SenderEntity entity) - { - return entity.isOffline(); - } - }; + public static final Predicate> PREDICATE_OFFLINE = SenderEntity::isOffline; public Collection getAllOnline() { diff --git a/src/com/massivecraft/massivecore/store/accessor/FieldAccessor.java b/src/com/massivecraft/massivecore/store/accessor/FieldAccessor.java index 557a94b4..6442ec57 100644 --- a/src/com/massivecraft/massivecore/store/accessor/FieldAccessor.java +++ b/src/com/massivecraft/massivecore/store/accessor/FieldAccessor.java @@ -2,7 +2,7 @@ package com.massivecraft.massivecore.store.accessor; public interface FieldAccessor { - public Object get(Object entity); - public void set(Object entity, Object val); + Object get(Object entity); + void set(Object entity, Object val); } diff --git a/src/com/massivecraft/massivecore/util/BoardUtil.java b/src/com/massivecraft/massivecore/util/BoardUtil.java index 3509c891..474fb1bb 100644 --- a/src/com/massivecraft/massivecore/util/BoardUtil.java +++ b/src/com/massivecraft/massivecore/util/BoardUtil.java @@ -251,14 +251,7 @@ public class BoardUtil extends Engine @EventHandler(priority = EventPriority.MONITOR) public void clean(final PlayerQuitEvent event) { - Bukkit.getScheduler().runTask(this.getPlugin(), new Runnable() - { - @Override - public void run() - { - clean(event.getPlayer()); - } - }); + Bukkit.getScheduler().runTask(this.getPlugin(), () -> clean(event.getPlayer())); } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/util/DiscUtil.java b/src/com/massivecraft/massivecore/util/DiscUtil.java index ca4a3d38..f1453540 100644 --- a/src/com/massivecraft/massivecore/util/DiscUtil.java +++ b/src/com/massivecraft/massivecore/util/DiscUtil.java @@ -7,6 +7,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; public class DiscUtil { @@ -111,28 +112,12 @@ public class DiscUtil public static byte[] utf8(String string) { - try - { - return string.getBytes(UTF8); - } - catch (UnsupportedEncodingException e) - { - e.printStackTrace(); - return null; - } + return string.getBytes(StandardCharsets.UTF_8); } public static String utf8(byte[] bytes) { - try - { - return new String(bytes, UTF8); - } - catch (UnsupportedEncodingException e) - { - e.printStackTrace(); - return null; - } + return new String(bytes, StandardCharsets.UTF_8); } } diff --git a/src/com/massivecraft/massivecore/util/IdUtil.java b/src/com/massivecraft/massivecore/util/IdUtil.java index bb4c26f1..a52e1016 100644 --- a/src/com/massivecraft/massivecore/util/IdUtil.java +++ b/src/com/massivecraft/massivecore/util/IdUtil.java @@ -94,7 +94,7 @@ public class IdUtil implements Listener, Runnable // IdData storage. Maintaining relation between name and id. // The full set - private static Set datas = Collections.newSetFromMap(new ConcurrentHashMap()); + private static Set datas = Collections.newSetFromMap(new ConcurrentHashMap<>()); public static Set getDatas() { return datas; } // Id Index @@ -358,14 +358,7 @@ public class IdUtil implements Listener, Runnable loadDatas(); // Since Console initially does not exist we schedule the register. - Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - register(getConsole()); - } - }); + Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), () -> register(getConsole())); // Cachefile long ticks = 20*60; // 5min diff --git a/src/com/massivecraft/massivecore/util/InventoryUtil.java b/src/com/massivecraft/massivecore/util/InventoryUtil.java index 1d74c5a6..f8764cc9 100644 --- a/src/com/massivecraft/massivecore/util/InventoryUtil.java +++ b/src/com/massivecraft/massivecore/util/InventoryUtil.java @@ -451,26 +451,12 @@ public class InventoryUtil public static void updateSoon(final HumanEntity human) { - Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - update(human); - } - }); + Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), () -> update(human)); } public static void updateLater(final HumanEntity human) { - Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), new Runnable() - { - @Override - public void run() - { - update(human); - } - }, 1); + Bukkit.getScheduler().scheduleSyncDelayedTask(MassiveCore.get(), () -> update(human), 1); } // -------------------------------------------- // @@ -1195,7 +1181,7 @@ public class InventoryUtil List> entries = event.getLore(); // Note: Comparator cast is necessary for Maven to compile, even if the IDE doesn't complain. Comparator> comparator = (Comparator) ComparatorEntryValue.get(ComparatorComparable.get()); - Collections.sort(entries, comparator); + entries.sort(comparator); List ret = new MassiveList<>(); for (Entry entry : entries) diff --git a/src/com/massivecraft/massivecore/util/MUtil.java b/src/com/massivecraft/massivecore/util/MUtil.java index 3c5d389a..77cec461 100644 --- a/src/com/massivecraft/massivecore/util/MUtil.java +++ b/src/com/massivecraft/massivecore/util/MUtil.java @@ -416,14 +416,7 @@ public class MUtil Collections.reverse(trace); // Eat Garbage - for (Iterator iterator = trace.iterator(); iterator.hasNext();) - { - StackTraceElement element = iterator.next(); - if (PredicateElementGarbage.get().apply(element)) - { - iterator.remove(); - } - } + trace.removeIf(PredicateElementGarbage.get()); // Unreverse Collections.reverse(trace); @@ -1467,7 +1460,7 @@ public class MUtil // ORDERBY if (orderby != null) { - Collections.sort(ret, orderby); + ret.sort(orderby); } // LIMIT AND OFFSET @@ -1593,13 +1586,8 @@ public class MUtil { K key = entry.getKey(); V value = entry.getValue(); - - Set set = ret.get(value); - if (set == null) - { - set = new HashSet<>(); - ret.put(value, set); - } + + Set set = ret.computeIfAbsent(value, k -> new HashSet<>()); set.add(key); } @@ -1799,22 +1787,17 @@ public class MUtil public static > SortedSet> entriesSortedByValues(Map map, final boolean ascending) { SortedSet> sortedEntries = new TreeSet<>( - new Comparator>() - { - @Override - public int compare(Map.Entry e1, Map.Entry e2) + (e1, e2) -> { + int res; + if (ascending) { - int res; - if (ascending) - { - res = e1.getValue().compareTo(e2.getValue()); - } - else - { - res = e2.getValue().compareTo(e1.getValue()); - } - return res != 0 ? res : 1; + res = e1.getValue().compareTo(e2.getValue()); } + else + { + res = e2.getValue().compareTo(e1.getValue()); + } + return res != 0 ? res : 1; } ); sortedEntries.addAll(map.entrySet()); @@ -1879,7 +1862,7 @@ public class MUtil { if (predicates.isEmpty()) throw new IllegalArgumentException("isEmpty"); - PredicateAnd predicate = new PredicateAnd(); + PredicateAnd predicate = new PredicateAnd<>(); predicate.predicates = new MassiveList<>(predicates); return predicate; diff --git a/src/com/massivecraft/massivecore/util/RecipeUtil.java b/src/com/massivecraft/massivecore/util/RecipeUtil.java index d8e06633..1a333492 100644 --- a/src/com/massivecraft/massivecore/util/RecipeUtil.java +++ b/src/com/massivecraft/massivecore/util/RecipeUtil.java @@ -84,7 +84,7 @@ public class RecipeUtil { if (object instanceof Integer) { - quantity = ((Integer)object).intValue(); + quantity = (Integer) object; } else { diff --git a/src/com/massivecraft/massivecore/util/ReflectionUtil.java b/src/com/massivecraft/massivecore/util/ReflectionUtil.java index 4d2d4ac0..2b7c70b6 100644 --- a/src/com/massivecraft/massivecore/util/ReflectionUtil.java +++ b/src/com/massivecraft/massivecore/util/ReflectionUtil.java @@ -15,8 +15,6 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; import java.util.List; import java.util.function.Predicate; @@ -414,33 +412,23 @@ public class ReflectionUtil public static Class getSuperclassDeclaringMethod(Class clazz, boolean includeSelf, final String methodName) { - return getSuperclassPredicate(clazz, includeSelf, new Predicate>() - { - @Override - public boolean test(Class clazz) + return getSuperclassPredicate(clazz, includeSelf, clazz1 -> { + for (Method method : clazz1.getDeclaredMethods()) { - for (Method method : clazz.getDeclaredMethods()) - { - if (method.getName().equals(methodName)) return true; - } - return false; + if (method.getName().equals(methodName)) return true; } + return false; }); } public static Class getSuperclassDeclaringField(Class clazz, boolean includeSelf, final String fieldName) { - return getSuperclassPredicate(clazz, includeSelf, new Predicate>() - { - @Override - public boolean test(Class clazz) + return getSuperclassPredicate(clazz, includeSelf, clazz1 -> { + for (Field field : clazz1.getDeclaredFields()) { - for (Field field : clazz.getDeclaredFields()) - { - if (field.getName().equals(fieldName)) return true; - } - return false; + if (field.getName().equals(fieldName)) return true; } + return false; }); } @@ -495,14 +483,7 @@ public class ReflectionUtil throw new RuntimeException(ex); } - Collections.sort(ret, new Comparator>() - { - @Override - public int compare(Class class1, Class class2) - { - return ComparatorNaturalOrder.get().compare(class1.getName(), class2.getName()); - } - }); + ret.sort((class1, class2) -> ComparatorNaturalOrder.get().compare(class1.getName(), class2.getName())); return ret; } @@ -517,7 +498,7 @@ public class ReflectionUtil if (t instanceof RuntimeException) return (RuntimeException) t; // Invocation - if (t instanceof InvocationTargetException) return asRuntimeException(((InvocationTargetException)t).getCause()); + if (t instanceof InvocationTargetException) return asRuntimeException(t.getCause()); // Rest return new IllegalStateException(t.getClass().getSimpleName() + ": " + t.getMessage()); diff --git a/src/com/massivecraft/massivecore/util/TimeDiffUtil.java b/src/com/massivecraft/massivecore/util/TimeDiffUtil.java index 8f2ec486..906833a1 100644 --- a/src/com/massivecraft/massivecore/util/TimeDiffUtil.java +++ b/src/com/massivecraft/massivecore/util/TimeDiffUtil.java @@ -78,7 +78,7 @@ public class TimeDiffUtil { // Parse the count String countString = matcherPart.group(1); - String countStringFixed = countString.replaceAll("[\\+\\s]", ""); + String countStringFixed = countString.replaceAll("[+\\s]", ""); long count = 0; try { diff --git a/src/com/massivecraft/massivecore/util/TimeUnit.java b/src/com/massivecraft/massivecore/util/TimeUnit.java index 48c271d0..66fc1906 100644 --- a/src/com/massivecraft/massivecore/util/TimeUnit.java +++ b/src/com/massivecraft/massivecore/util/TimeUnit.java @@ -156,7 +156,7 @@ public class TimeUnit implements Comparable @Override public int compareTo(TimeUnit that) { - return Long.valueOf(this.millis).compareTo(that.millis) * -1; + return Long.compare(this.millis, that.millis) * -1; } @Override diff --git a/src/com/massivecraft/massivecore/util/WebUtil.java b/src/com/massivecraft/massivecore/util/WebUtil.java index 9afa16ac..77abb74a 100644 --- a/src/com/massivecraft/massivecore/util/WebUtil.java +++ b/src/com/massivecraft/massivecore/util/WebUtil.java @@ -13,6 +13,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; @@ -55,14 +56,7 @@ public class WebUtil } else { - EXECUTOR.execute(new Runnable() - { - @Override - public void run() - { - touch(url); - } - }); + EXECUTOR.execute(() -> touch(url)); } } @@ -105,7 +99,7 @@ public class WebUtil uc.connect(); is = uc.getInputStream(); - isr = new InputStreamReader(is, "UTF-8"); + isr = new InputStreamReader(is, StandardCharsets.UTF_8); br = new BufferedReader(isr); List lines = new ArrayList<>();