From 61bea411f5b18123192f4a28348ac1f819d81138 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Fri, 3 May 2019 09:25:18 +0200 Subject: [PATCH] Code cleanup --- src/com/massivecraft/factions/Factions.java | 2 - .../massivecraft/factions/FactionsIndex.java | 2 +- src/com/massivecraft/factions/Rel.java | 3 +- .../cmd/CmdFactionsAccessSetFill.java | 3 +- .../factions/cmd/CmdFactionsAccessSetOne.java | 3 +- .../factions/cmd/CmdFactionsFaction.java | 31 ++-- .../factions/cmd/CmdFactionsFlagList.java | 47 ++---- .../factions/cmd/CmdFactionsFlagShow.java | 9 +- .../factions/cmd/CmdFactionsInviteList.java | 45 ++---- .../factions/cmd/CmdFactionsList.java | 51 +++---- .../factions/cmd/CmdFactionsMap.java | 3 +- .../factions/cmd/CmdFactionsPermList.java | 23 ++- .../factions/cmd/CmdFactionsPermShow.java | 2 +- .../factions/cmd/CmdFactionsRankList.java | 2 +- .../factions/cmd/CmdFactionsRankSet.java | 4 +- .../factions/cmd/CmdFactionsRelationList.java | 50 +++---- .../cmd/CmdFactionsRelationWishes.java | 56 +++---- .../factions/cmd/CmdFactionsSeeChunkOld.java | 3 +- .../factions/cmd/CmdFactionsSetOne.java | 3 +- .../factions/cmd/CmdFactionsStatus.java | 79 +++++----- .../factions/cmd/CmdFactionsTop.java | 17 +-- .../factions/cmd/type/TypeMPermable.java | 15 +- .../engine/EngineCanCombatHappen.java | 2 - .../factions/engine/EngineExploit.java | 3 +- .../factions/engine/EngineFlagExplosion.java | 12 +- .../factions/engine/EngineLastActivity.java | 9 +- .../factions/engine/EngineMotd.java | 9 +- .../factions/engine/EnginePermBuild.java | 139 +++++++++++------- .../factions/engine/EngineShow.java | 2 +- .../engine/EngineTeleportHomeOnDeath.java | 2 +- .../massivecraft/factions/entity/Faction.java | 4 +- .../factions/entity/FactionColl.java | 4 +- .../massivecraft/factions/entity/MPerm.java | 7 +- .../massivecraft/factions/entity/Rank.java | 1 - .../massivecraft/factions/entity/Vote.java | 3 +- .../massivecraft/factions/entity/Warp.java | 3 +- .../event/EventFactionsChunksChange.java | 1 - .../factions/integration/V18/EngineV18.java | 55 ------- .../integration/V18/IntegrationV18.java | 31 ---- .../factions/integration/lwc/EngineLwc.java | 18 +-- .../integration/spigot/EngineSpigot.java | 123 ---------------- .../integration/spigot/IntegrationSpigot.java | 29 ---- .../integration/spigot/PredicateSpigot.java | 36 ----- .../factions/util/VisualizeUtil.java | 8 +- 44 files changed, 288 insertions(+), 666 deletions(-) delete mode 100644 src/com/massivecraft/factions/integration/V18/EngineV18.java delete mode 100644 src/com/massivecraft/factions/integration/V18/IntegrationV18.java delete mode 100644 src/com/massivecraft/factions/integration/spigot/EngineSpigot.java delete mode 100644 src/com/massivecraft/factions/integration/spigot/IntegrationSpigot.java delete mode 100644 src/com/massivecraft/factions/integration/spigot/PredicateSpigot.java diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 0be282b8..d697bfcd 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -66,7 +66,6 @@ import com.massivecraft.factions.entity.migrator.MigratorMPlayer001Ranks; import com.massivecraft.factions.entity.migrator.MigratorMPlayer002UsingAdminMode; import com.massivecraft.factions.entity.migrator.MigratorTerritoryAccess001Restructure; import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.integration.V18.IntegrationV18; import com.massivecraft.factions.integration.V19.IntegrationV19; import com.massivecraft.factions.integration.lwc.IntegrationLwc; import com.massivecraft.factions.integration.placeholderapi.IntegrationPlaceholderAPI; @@ -196,7 +195,6 @@ public class Factions extends MassivePlugin return MUtil.list( IntegrationPlaceholderAPI.class, IntegrationVentureChat.class, - IntegrationV18.class, IntegrationV19.class, IntegrationLwc.class, IntegrationWorldGuard.class diff --git a/src/com/massivecraft/factions/FactionsIndex.java b/src/com/massivecraft/factions/FactionsIndex.java index 9f7bc2d2..62441ddd 100644 --- a/src/com/massivecraft/factions/FactionsIndex.java +++ b/src/com/massivecraft/factions/FactionsIndex.java @@ -153,7 +153,7 @@ public class FactionsIndex @Override public Set createValue() { - return Collections.newSetFromMap(new WeakHashMap()); + return Collections.newSetFromMap(new WeakHashMap<>()); } } diff --git a/src/com/massivecraft/factions/Rel.java b/src/com/massivecraft/factions/Rel.java index cc4f7cb8..1603f2ad 100644 --- a/src/com/massivecraft/factions/Rel.java +++ b/src/com/massivecraft/factions/Rel.java @@ -150,7 +150,8 @@ public enum Rel implements Colorized, Named, MPerm.MPermable { return this.isAtLeast(TRUCE); } - + + @Deprecated public String getPrefix() { return ""; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java index 25dd1803..678f8334 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java @@ -7,12 +7,11 @@ import com.massivecraft.factions.entity.MConf; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.util.ChunkUtil; import java.util.Set; - +import java.util.function.Predicate; public class CmdFactionsAccessSetFill extends CmdFactionsAccessSetXSimple { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java index 670496d2..db48973c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java @@ -37,8 +37,7 @@ public class CmdFactionsAccessSetOne extends CmdFactionsAccessSetXSimple public Set getChunks() { final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - final Set chunks = Collections.singleton(chunk); - return chunks; + return Collections.singleton(chunk); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java index f7ae98e7..cee7de79 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java @@ -39,25 +39,20 @@ public class CmdFactionsFaction extends FactionsCommand final Faction faction = this.readArg(msenderFaction); final CommandSender sender = this.sender; - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() - { - @Override - public void run() + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Event + EventFactionsFactionShowAsync event = new EventFactionsFactionShowAsync(sender, faction); + event.run(); + if (event.isCancelled()) return; + + // Title + MixinMessage.get().messageOne(sender, Txt.titleize("Faction " + faction.getName(msender))); + + // Lines + TreeSet priorityLiness = new TreeSet<>(event.getIdPriorityLiness().values()); + for (PriorityLines priorityLines : priorityLiness) { - // Event - EventFactionsFactionShowAsync event = new EventFactionsFactionShowAsync(sender, faction); - event.run(); - if (event.isCancelled()) return; - - // Title - MixinMessage.get().messageOne(sender, Txt.titleize("Faction " + faction.getName(msender))); - - // Lines - TreeSet priorityLiness = new TreeSet<>(event.getIdPriorityLiness().values()); - for (PriorityLines priorityLines : priorityLiness) - { - MixinMessage.get().messageOne(sender, priorityLines.getLines()); - } + MixinMessage.get().messageOne(sender, priorityLines.getLines()); } }); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java index f2066265..c4bb34d0 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java @@ -1,9 +1,5 @@ package com.massivecraft.factions.cmd; -import java.util.List; - -import org.bukkit.Bukkit; - import com.massivecraft.factions.Factions; import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlagColl; @@ -12,7 +8,9 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.Parameter; import com.massivecraft.massivecore.pager.Pager; import com.massivecraft.massivecore.pager.Stringifier; -import com.massivecraft.massivecore.predicate.Predicate; +import org.bukkit.Bukkit; + +import java.util.List; public class CmdFactionsFlagList extends FactionsCommand { @@ -39,36 +37,17 @@ public class CmdFactionsFlagList extends FactionsCommand // Pager create String title = "Flag List for " + msenderFaction.describeTo(mplayer); - final Pager pager = new Pager<>(this, title, page, new Stringifier() - { - @Override - public String toString(MFlag mflag, int index) - { - return mflag.getStateDesc(false, false, true, true, true, false); - } - }); + final Pager pager = new Pager<>(this, title, page, (Stringifier) (mflag, index) -> mflag.getStateDesc(false, false, true, true, true, false)); - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() - { - @Override - public void run() - { - // Get items - List items = MFlagColl.get().getAll(mplayer.isOverriding() ? null : new Predicate() - { - @Override - public boolean apply(MFlag mflag) - { - return mflag.isVisible(); - } - }); - - // Pager items - pager.setItems(items); - - // Pager message - pager.message(); - } + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Get items + List items = MFlagColl.get().getAll(mplayer.isOverriding() ? null : MFlag::isVisible); + + // Pager items + pager.setItems(items); + + // Pager message + pager.message(); }); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java index 59c9bea5..249e24a7 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java @@ -37,14 +37,7 @@ public class CmdFactionsFlagShow extends FactionsCommand // Pager create String title = "Flags for " + faction.describeTo(msender); - Pager pager = new Pager<>(this, title, page, MFlag.getAll(), new Stringifier() - { - @Override - public String toString(MFlag mflag, int index) - { - return mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true); - } - }); + Pager pager = new Pager<>(this, title, page, MFlag.getAll(), (Stringifier) (mflag, index) -> mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true)); // Pager args List pagerArgs = new MassiveList<>( diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java b/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java index f72f94cf..f577a7b7 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java @@ -16,8 +16,6 @@ import com.massivecraft.massivecore.util.TimeDiffUtil; import com.massivecraft.massivecore.util.TimeUnit; import com.massivecraft.massivecore.util.Txt; -import java.util.Collections; -import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map.Entry; @@ -55,38 +53,27 @@ public class CmdFactionsInviteList extends FactionsCommand // Pager Create final List> invitations = new MassiveList<>(faction.getInvitations().entrySet()); - Collections.sort(invitations, new Comparator>() - { - @Override - public int compare(Entry i1, Entry i2) - { - return ComparatorSmart.get().compare(i2.getValue().getCreationMillis(), i1.getValue().getCreationMillis()); - } - }); + invitations.sort((i1, i2) -> ComparatorSmart.get().compare(i2.getValue().getCreationMillis(), i1.getValue().getCreationMillis())); final long now = System.currentTimeMillis(); - final Pager> pager = new Pager<>(this, "Invited Players List", page, invitations, new Stringifier>() - { - public String toString(Entry entry, int index) - { - String inviteeId = entry.getKey(); - String inviterId = entry.getValue().getInviterId(); - - String inviteeDisplayName = MixinDisplayName.get().getDisplayName(inviteeId, sender); - String inviterDisplayName = inviterId != null ? MixinDisplayName.get().getDisplayName(inviterId, sender) : Txt.parse("unknown"); - - String ageDesc = ""; - if (entry.getValue().getCreationMillis() != null) - { - long millis = now - entry.getValue().getCreationMillis(); - LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(millis, TimeUnit.getAllButMillis()), 2); - ageDesc = TimeDiffUtil.formatedMinimal(ageUnitcounts, ""); - ageDesc = " " + ageDesc + Txt.parse(" ago"); - } + final Pager> pager = new Pager<>(this, "Invited Players List", page, invitations, (Stringifier>) (entry, index) -> { + String inviteeId = entry.getKey(); + String inviterId = entry.getValue().getInviterId(); - return Txt.parse("%s was invited by %s%s.", inviteeDisplayName, inviterDisplayName, ageDesc); + String inviteeDisplayName = MixinDisplayName.get().getDisplayName(inviteeId, sender); + String inviterDisplayName = inviterId != null ? MixinDisplayName.get().getDisplayName(inviterId, sender) : Txt.parse("unknown"); + + String ageDesc = ""; + if (entry.getValue().getCreationMillis() != null) + { + long millis = now - entry.getValue().getCreationMillis(); + LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(millis, TimeUnit.getAllButMillis()), 2); + ageDesc = TimeDiffUtil.formatedMinimal(ageUnitcounts, ""); + ageDesc = " " + ageDesc + Txt.parse(" ago"); } + + return Txt.parse("%s was invited by %s%s.", inviteeDisplayName, inviterDisplayName, ageDesc); }); // Pager Message diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java index ac78b5ee..0b99ed99 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -43,40 +43,31 @@ public class CmdFactionsList extends FactionsCommand // We run it asynchronously to spare the primary server thread. // Pager Create - final Pager pager = new Pager<>(this, "Faction List", page, new Stringifier() { - @Override - public String toString(Faction faction, int index) + final Pager pager = new Pager<>(this, "Faction List", page, (Stringifier) (faction, index) -> { + if (faction.isNone()) { - if (faction.isNone()) - { - return Txt.parse("Factionless %d online", FactionColl.get().getNone().getMPlayersWhereOnlineTo(sender).size()); - } - else - { - return Txt.parse("%s %d/%d online, %d/%d/%d", - faction.getName(msender), - faction.getMPlayersWhereOnlineTo(sender).size(), - faction.getMPlayers().size(), - faction.getLandCount(), - faction.getPowerRounded(), - faction.getPowerMaxRounded() - ); - } + return Txt.parse("Factionless %d online", FactionColl.get().getNone().getMPlayersWhereOnlineTo(sender).size()); + } + else + { + return Txt.parse("%s %d/%d online, %d/%d/%d", + faction.getName(msender), + faction.getMPlayersWhereOnlineTo(sender).size(), + faction.getMPlayers().size(), + faction.getLandCount(), + faction.getPowerRounded(), + faction.getPowerMaxRounded() + ); } }); - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() - { - @Override - public void run() - { - // Pager Items - final List factions = FactionColl.get().getAll(ComparatorFactionList.get(sender)); - pager.setItems(factions); - - // Pager Message - pager.message(); - } + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Pager Items + final List factions = FactionColl.get().getAll(ComparatorFactionList.get(sender)); + pager.setItems(factions); + + // Pager Message + pager.message(); }); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index 55517c3e..10d5b00f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.util.AsciiMap; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; +import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.util.Txt; public class CmdFactionsMap extends FactionsCommand @@ -37,7 +38,7 @@ public class CmdFactionsMap extends FactionsCommand if (!showMap) return; // Show Map - AsciiMap map = new AsciiMap(msender, me, !argSet); + AsciiMap map = new AsciiMap(msender, PS.valueOf(me), !argSet); message(map.render()); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java index ba8057dd..3d12e66c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java @@ -39,20 +39,15 @@ public class CmdFactionsPermList extends FactionsCommand final Pager pager = new Pager<>(this, title, page, (Stringifier) (mp, i) -> mp.getDesc(true, true)); final Predicate predicate = msender.isOverriding() ? null : MPerm::isVisible; - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() - { - @Override - public void run() - { - // Get items - List items = MPermColl.get().getAll(predicate); - - // Pager items - pager.setItems(items); - - // Pager message - pager.message(); - } + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Get items + List items = MPermColl.get().getAll(predicate); + + // Pager items + pager.setItems(items); + + // Pager message + pager.message(); }); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java index 0cc716ce..d919ed08 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java @@ -44,7 +44,7 @@ public class CmdFactionsPermShow extends FactionsCommand for (String permitted : permittedIds) { - permables.add(idToMPermable(permitted)); + permables.add(MPerm.idToMPermable(permitted)); } String removeString = Txt.parse(" of ") + faction.getDisplayName(msender); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java index 9efc5159..0ccdabec 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java @@ -37,7 +37,7 @@ public class CmdFactionsRankList extends FactionsCommand List ranks = faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority).reversed()); String title = "Rank list for " + faction.describeTo(msender); - Pager pager = new Pager(this, title, page, ranks, (Stringifier) (r, i) -> r.getVisual()); + Pager pager = new Pager<>(this, title, page, ranks, (Stringifier) (r, i) -> r.getVisual()); pager.message(); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java index 95ecc156..7bbfe374 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java @@ -15,6 +15,7 @@ import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.EventFactionsRankChange; import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.util.Txt; import java.util.HashSet; @@ -317,8 +318,7 @@ public class CmdFactionsRankSet extends FactionsCommand } // Create recipients - Set recipients = new HashSet<>(); - recipients.addAll(targetFaction.getMPlayers()); + Set recipients = new MassiveSet<>(targetFaction.getMPlayers()); recipients.add(msender); // Were they demoted or promoted? diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java index cdb77864..4068e431 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java @@ -54,42 +54,30 @@ public class CmdFactionsRelationList extends FactionsCommand final Set relations = this.readArg(RELEVANT_RELATIONS); // Pager Create - final Pager pager = new Pager<>(this, "", page, new Stringifier() - { - @Override - public String toString(String item, int index) - { - return item; - } - }); + final Pager pager = new Pager<>(this, "", page, (Stringifier) (item, index) -> item); - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() - { - @Override - public void run() + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Prepare Items + List relNames = new MassiveList<>(); + for (Entry> entry : FactionColl.get().getRelationNames(faction, relations).entrySet()) { - // Prepare Items - List relNames = new MassiveList<>(); - for (Entry> entry : FactionColl.get().getRelationNames(faction, relations).entrySet()) + Rel relation = entry.getKey(); + String coloredName = relation.getColor().toString() + relation.getName(); + + for (String name : entry.getValue()) { - Rel relation = entry.getKey(); - String coloredName = relation.getColor().toString() + relation.getName(); - - for (String name : entry.getValue()) - { - relNames.add(coloredName + SEPERATOR + name); - } + relNames.add(coloredName + SEPERATOR + name); } - - // Pager Title - pager.setTitle(Txt.parse("%s's Relations (%d)", faction.getName(), relNames.size())); - - // Pager Items - pager.setItems(relNames); - - // Pager Message - pager.message(); } + + // Pager Title + pager.setTitle(Txt.parse("%s's Relations (%d)", faction.getName(), relNames.size())); + + // Pager Items + pager.setItems(relNames); + + // Pager Message + pager.message(); }); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java index d85f69cf..7fb551f4 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java @@ -42,44 +42,34 @@ public class CmdFactionsRelationWishes extends FactionsCommand final Faction faction = this.readArg(msenderFaction); // Pager Create - final Pager> pager = new Pager<>(this, "", page, new Stringifier>() - { - @Override - public String toString(Entry item, int index) - { - Rel rel = item.getValue(); - Faction fac = item.getKey(); - return rel.getColor().toString() + rel.getName() + CmdFactionsRelationList.SEPERATOR + fac.describeTo(faction, true); - } + final Pager> pager = new Pager<>(this, "", page, (Stringifier>) (item, index) -> { + Rel rel = item.getValue(); + Faction fac = item.getKey(); + return rel.getColor().toString() + rel.getName() + CmdFactionsRelationList.SEPERATOR + fac.describeTo(faction, true); }); - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() - { - @Override - public void run() + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + Map realWishes = new MassiveMap<>(); + + for (Entry entry : faction.getRelationWishes().entrySet()) { - Map realWishes = new MassiveMap<>(); + Rel rel = entry.getValue(); + Faction fac = FactionColl.get().getFixed(entry.getKey()); + if (fac == null) continue; - for (Entry entry : faction.getRelationWishes().entrySet()) - { - Rel rel = entry.getValue(); - Faction fac = FactionColl.get().getFixed(entry.getKey()); - if (fac == null) continue; - - // A wish is not a wish anymore if both factions have atleast equal "wishes" - if (fac.getRelationTo(faction).isAtLeast(rel)) continue; - realWishes.put(fac, rel); - } - - // Pager Title - pager.setTitle(Txt.parse("%s's Relation wishes (%d)", faction.getName(), realWishes.size())); - - // Pager Items - pager.setItems(MUtil.entriesSortedByValues(realWishes)); - - // Pager Message - pager.message(); + // A wish is not a wish anymore if both factions have atleast equal "wishes" + if (fac.getRelationTo(faction).isAtLeast(rel)) continue; + realWishes.put(fac, rel); } + + // Pager Title + pager.setTitle(Txt.parse("%s's Relation wishes (%d)", faction.getName(), realWishes.size())); + + // Pager Items + pager.setItems(MUtil.entriesSortedByValues(realWishes)); + + // Pager Message + pager.message(); }); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java b/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java index 96bf5777..3acde462 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java @@ -60,8 +60,7 @@ public class CmdFactionsSeeChunkOld extends FactionsCommand // Inform msg("Visualized %s", chunk.toString(PSFormatHumanSpace.get())); } - - @SuppressWarnings("deprecation") + public static void showPillar(Player player, World world, int blockX, int blockZ) { for (int blockY = 0; blockY < world.getMaxHeight(); blockY++) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetOne.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetOne.java index fa871112..102b5ed9 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetOne.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsSetOne.java @@ -37,8 +37,7 @@ public class CmdFactionsSetOne extends CmdFactionsSetXSimple public Set getChunks() { final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - final Set chunks = Collections.singleton(chunk); - return chunks; + return Collections.singleton(chunk); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java b/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java index 5985c9d9..3609bc71 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java @@ -46,53 +46,48 @@ public class CmdFactionsStatus extends FactionsCommand // Sort list final List mplayers = faction.getMPlayers(); - Collections.sort(mplayers, sortedBy); + mplayers.sort(sortedBy); // Pager Create String title = Txt.parse("Status of %s.", faction.describeTo(msender, true)); - final Pager pager = new Pager<>(this, title, page, mplayers, new Stringifier() - { - @Override - public String toString(MPlayer mplayer, int index) + final Pager pager = new Pager<>(this, title, page, mplayers, (Stringifier) (mplayer, index) -> { + // Name + String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); + int length = 15 - displayName.length(); + length = length <= 0 ? 1 : length; + String whiteSpace = Txt.repeat(" ", length); + + // Power + double currentPower = mplayer.getPower(); + double maxPower = mplayer.getPowerMax(); + String color; + double percent = currentPower / maxPower; + + if (percent > 0.75) { - // Name - String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); - int length = 15 - displayName.length(); - length = length <= 0 ? 1 : length; - String whiteSpace = Txt.repeat(" ", length); - - // Power - double currentPower = mplayer.getPower(); - double maxPower = mplayer.getPowerMax(); - String color; - double percent = currentPower / maxPower; - - if (percent > 0.75) - { - color = ""; - } - else if (percent > 0.5) - { - color = ""; - } - else if (percent > 0.25) - { - color = ""; - } - else - { - color = ""; - } - - String power = Txt.parse("Power: %s%.0f/%.0f", Txt.parse(color), currentPower, maxPower); - - // Time - long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); - LinkedHashMap activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); - String lastActive = mplayer.isOnline(msender) ? Txt.parse("Online right now.") : Txt.parse("Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "")); - - return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); + color = ""; } + else if (percent > 0.5) + { + color = ""; + } + else if (percent > 0.25) + { + color = ""; + } + else + { + color = ""; + } + + String power = Txt.parse("Power: %s%.0f/%.0f", Txt.parse(color), currentPower, maxPower); + + // Time + long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); + LinkedHashMap activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); + String lastActive = mplayer.isOnline(msender) ? Txt.parse("Online right now.") : Txt.parse("Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "")); + + return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); }); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTop.java b/src/com/massivecraft/factions/cmd/CmdFactionsTop.java index 1e0d3f0a..df7426de 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTop.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTop.java @@ -57,18 +57,13 @@ public class CmdFactionsTop extends FactionsCommand // NOTE: The faction list is quite slow and mostly thread safe. // We run it asynchronously to spare the primary server thread. - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() - { - @Override - public void run() - { - // Pager Items - List factions = FactionColl.get().getAll((f1, f2) -> (int) (getNumber(category, f2) - getNumber(category, f1))); - pager.setItems(factions); + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Pager Items + List factions = FactionColl.get().getAll((f1, f2) -> (int) (getNumber(category, f2) - getNumber(category, f1))); + pager.setItems(factions); - // Pager Message - pager.message(); - } + // Pager Message + pager.message(); }); } diff --git a/src/com/massivecraft/factions/cmd/type/TypeMPermable.java b/src/com/massivecraft/factions/cmd/type/TypeMPermable.java index def781e1..2e159319 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeMPermable.java +++ b/src/com/massivecraft/factions/cmd/type/TypeMPermable.java @@ -81,8 +81,7 @@ public class TypeMPermable extends TypeAbstract TypeRank typeRank = new TypeRank(this.getFaction()); try { - Rank rank = typeRank.read(arg, sender); - return rank; + return typeRank.read(arg, sender); } catch (MassiveException ex) { @@ -91,8 +90,7 @@ public class TypeMPermable extends TypeAbstract try { - Rel rel = TypeRelation.get().read(arg, sender); - return rel; + return TypeRelation.get().read(arg, sender); } catch (MassiveException ex) { @@ -101,8 +99,7 @@ public class TypeMPermable extends TypeAbstract try { - MPlayer mplayer = TypeMPlayer.get().read(arg, sender); - return mplayer; + return TypeMPlayer.get().read(arg, sender); } catch (MassiveException ex) { @@ -111,8 +108,7 @@ public class TypeMPermable extends TypeAbstract try { - Faction faction = TypeFaction.get().read(arg, sender); - return faction; + return TypeFaction.get().read(arg, sender); } catch (MassiveException ex) { @@ -126,8 +122,7 @@ public class TypeMPermable extends TypeAbstract String rankName = arg.substring(idx+1); Faction faction = TypeFaction.get().read(factionName, sender); - Rank rank = TypeRank.get(faction).read(rankName, sender); - return rank; + return TypeRank.get(faction).read(rankName, sender); } throw new MassiveException().addMsg("No rank, relation, player or faction matches: %s.", arg); diff --git a/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java b/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java index 3b237651..a8d0e303 100644 --- a/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java +++ b/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java @@ -48,7 +48,6 @@ public class EngineCanCombatHappen extends Engine } // mainly for flaming arrows; don't want allies or people in safe zones to be ignited even after damage event is cancelled - @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void canCombatDamageHappen(EntityCombustByEntityEvent event) { @@ -57,7 +56,6 @@ public class EngineCanCombatHappen extends Engine event.setCancelled(true); } - @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void canCombatDamageHappen(PotionSplashEvent event) { diff --git a/src/com/massivecraft/factions/engine/EngineExploit.java b/src/com/massivecraft/factions/engine/EngineExploit.java index 70d0d917..ed6086f1 100644 --- a/src/com/massivecraft/factions/engine/EngineExploit.java +++ b/src/com/massivecraft/factions/engine/EngineExploit.java @@ -33,8 +33,7 @@ public class EngineExploit extends Engine // -------------------------------------------- // // OBSIDIAN GENERATORS // -------------------------------------------- // - - @SuppressWarnings("deprecation") + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void obsidianGenerators(BlockFromToEvent event) { diff --git a/src/com/massivecraft/factions/engine/EngineFlagExplosion.java b/src/com/massivecraft/factions/engine/EngineFlagExplosion.java index 5a32f14e..0693e3c4 100644 --- a/src/com/massivecraft/factions/engine/EngineFlagExplosion.java +++ b/src/com/massivecraft/factions/engine/EngineFlagExplosion.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Wither; import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; @@ -23,7 +24,6 @@ import java.util.Collection; import java.util.EnumSet; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Set; @@ -133,4 +133,14 @@ public class EngineFlagExplosion extends Engine event.setCancelled(true); } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockExplosion(BlockExplodeEvent event) + { + Location location = event.getBlock().getLocation(); + Cancellable cancellable = event; + Collection blocks = event.blockList(); + + EngineFlagExplosion.get().blockExplosion(location, cancellable, blocks); + } + } diff --git a/src/com/massivecraft/factions/engine/EngineLastActivity.java b/src/com/massivecraft/factions/engine/EngineLastActivity.java index a98944ff..3e802893 100644 --- a/src/com/massivecraft/factions/engine/EngineLastActivity.java +++ b/src/com/massivecraft/factions/engine/EngineLastActivity.java @@ -36,14 +36,7 @@ public class EngineLastActivity extends Engine public static void updateLastActivitySoon(final CommandSender sender) { if (sender == null) throw new RuntimeException("sender"); - Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), new Runnable() - { - @Override - public void run() - { - updateLastActivity(sender); - } - }); + Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> updateLastActivity(sender)); } // Can't be cancelled diff --git a/src/com/massivecraft/factions/engine/EngineMotd.java b/src/com/massivecraft/factions/engine/EngineMotd.java index 3bece99c..38fa2711 100644 --- a/src/com/massivecraft/factions/engine/EngineMotd.java +++ b/src/com/massivecraft/factions/engine/EngineMotd.java @@ -56,14 +56,7 @@ public class EngineMotd extends Engine } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), new Runnable() - { - @Override - public void run() - { - MixinMessage.get().messageOne(player, messages); - } - }, MConf.get().motdDelayTicks); + Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> MixinMessage.get().messageOne(player, messages), MConf.get().motdDelayTicks); } } diff --git a/src/com/massivecraft/factions/engine/EnginePermBuild.java b/src/com/massivecraft/factions/engine/EnginePermBuild.java index 98207039..4ffc7b0f 100644 --- a/src/com/massivecraft/factions/engine/EnginePermBuild.java +++ b/src/com/massivecraft/factions/engine/EnginePermBuild.java @@ -9,7 +9,6 @@ import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.integration.spigot.IntegrationSpigot; import com.massivecraft.factions.util.EnumerationUtil; import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.ps.PS; @@ -18,6 +17,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.Cancellable; @@ -38,10 +38,12 @@ import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.projectiles.ProjectileSource; +import java.util.List; import java.util.Map; public class EnginePermBuild extends Engine @@ -192,7 +194,30 @@ public class EnginePermBuild extends Engine if (isOffHand(event)) return; useEntity(event.getPlayer(), event.getRightClicked(), true, event); } - + + // This is a special Spigot event that fires for Minecraft 1.8 armor stands. + // It also fires for other entity types but for those the event is buggy. + // It seems we can only cancel interaction with armor stands from here. + // Thus we only handle armor stands from here and handle everything else in EngineMain. + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void handleArmorStand(PlayerInteractAtEntityEvent event) + { + // Ignore Off Hand + if (isOffHand(event)) return; + + // Gather Info + final Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) return; + final Entity entity = event.getRightClicked(); + final boolean verboose = true; + + // Only care for armor stands. + if (entity.getType() != EntityType.ARMOR_STAND) return; + + // If we can't use, block it + EnginePermBuild.useEntity(player, entity, verboose, event); + } + // -------------------------------------------- // // BUILD > ENTITY // -------------------------------------------- // @@ -237,61 +262,67 @@ public class EnginePermBuild extends Engine // BUILD > PISTON // -------------------------------------------- // - /* - * NOTE: These piston listeners are only called on 1.7 servers. - * - * Originally each affected block in the territory was tested, but since we found that pistons can only push - * up to 12 blocks and the width of any territory is 16 blocks, it should be safe (and much more lightweight) to test - * only the final target block as done below. - */ + /* + * Note: With 1.8 and the slime blocks, retracting and extending pistons + * became more of a problem. Blocks located on the border of a chunk + * could have easily been stolen. That is the reason why every block + * needs to be checked now, whether he moved into a territory which + * he actually may not move into. + */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void buildPiston(BlockPistonExtendEvent event) + public void blockBuild(BlockPistonExtendEvent event) { - // Is using Spigot or is checking deactivated by MConf? - if (IntegrationSpigot.get().isIntegrationActive() || !MConf.get().handlePistonProtectionThroughDenyBuild) return; - - // Targets end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air - Block block = event.getBlock(); - Block targetBlock = block.getRelative(event.getDirection(), event.getLength() + 1); - - // Factions involved - Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(block)); - Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetBlock)); - - // Members of a faction might not have build rights in their own territory, but pistons should still work regardless - if (targetFaction == pistonFaction) return; - - // If potentially pushing into air/water/lava in another territory, we need to check it out - if (!targetBlock.isEmpty() && !targetBlock.isLiquid()) return; - if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) return; - - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void buildPiston(BlockPistonRetractEvent event) - { - // Is using Spigot or is checking deactivated by MConf? - if (IntegrationSpigot.get().isIntegrationActive() || ! MConf.get().handlePistonProtectionThroughDenyBuild) return; - - // If not a sticky piston, retraction should be fine - if ( ! event.isSticky()) return; - - Block retractBlock = event.getRetractLocation().getBlock(); - PS retractPs = PS.valueOf(retractBlock); - - // if potentially retracted block is just air/water/lava, no worries - if (retractBlock.isEmpty() || retractBlock.isLiquid()) return; - - // Factions involved + // Is checking deactivated by MConf? + if ( ! MConf.get().handlePistonProtectionThroughDenyBuild) return; + Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); - Faction targetFaction = BoardColl.get().getFactionAt(retractPs); - - // Members of a faction might not have build rights in their own territory, but pistons should still work regardless - if (targetFaction == pistonFaction) return; - if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) return; - - event.setCancelled(true); + + List blocks = event.getBlocks(); + + // Check for all extended blocks + for (Block block : blocks) + { + // Block which is being pushed into + Block targetBlock = block.getRelative(event.getDirection()); + + // Members of a faction might not have build rights in their own territory, but pistons should still work regardless + Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetBlock)); + if (targetFaction == pistonFaction) continue; + + // Perm check + if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) continue; + + event.setCancelled(true); + return; + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockBuild(BlockPistonRetractEvent event) + { + // Is checking deactivated by MConf? + if ( ! MConf.get().handlePistonProtectionThroughDenyBuild) return; + + Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); + + List blocks = event.getBlocks(); + + // Check for all retracted blocks + for (Block block : blocks) + { + // Is the retracted block air/water/lava? Don't worry about it + if (block.isEmpty() || block.isLiquid()) return; + + // Members of a faction might not have build rights in their own territory, but pistons should still work regardless + Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(block)); + if (targetFaction == pistonFaction) continue; + + // Perm check + if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) continue; + + event.setCancelled(true); + return; + } } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/engine/EngineShow.java b/src/com/massivecraft/factions/engine/EngineShow.java index 9780b99e..abdea511 100644 --- a/src/com/massivecraft/factions/engine/EngineShow.java +++ b/src/com/massivecraft/factions/engine/EngineShow.java @@ -167,7 +167,7 @@ public class EngineShow extends Engine List followerNamesOffline = new ArrayList<>(); List followers = faction.getMPlayers(); - Collections.sort(followers, ComparatorMPlayerRole.get()); + followers.sort(ComparatorMPlayerRole.get()); for (MPlayer follower : followers) { if (follower.isOnline(sender)) diff --git a/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java b/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java index 380e4fac..02b99064 100644 --- a/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java +++ b/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java @@ -44,7 +44,7 @@ public class EngineTeleportHomeOnDeath extends Engine if (faction.isNone()) return; // ... and the faction has a home ... - List warps = faction.getWarps().getAll(warp -> warp.getName().equalsIgnoreCase(MConf.get().warpsTeleportToOnDeathName)); + List warps = faction.getWarps().getAll((java.util.function.Predicate) (warp -> warp.getName().equalsIgnoreCase(MConf.get().warpsTeleportToOnDeathName))); if (warps.isEmpty()) return; Warp warp = warps.get(0); diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 349a2dc2..87b5af99 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -187,9 +187,7 @@ public class Faction extends Entity implements FactionsParticipator, MP @Override public String getName() { - String ret = this.name; - - return ret; + return this.name; } public void setName(String name) diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index 01d759a8..840b69b1 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -90,7 +90,7 @@ public class FactionColl extends Coll faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));; + faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermDeposit(), Collections.singleton(faction.getLeaderRank())); // Wilderness deposit should be limited as an anti spam meassure. return faction; @@ -233,7 +233,7 @@ public class FactionColl extends Coll boolean peaceful = faction.getFlag(flagPeaceful); for (Rel rel : rels) { - ret.put(rel, new ArrayList()); + ret.put(rel, new ArrayList<>()); } // Fill diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index 092b0714..d8193e74 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -146,7 +146,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N } public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", MUtil.set("LEADER", "OFFICER", "MEMBER"), true, true, true); } - public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", new MassiveSet(), true, true, true); } + public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", new MassiveSet<>(), true, true, true); } public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), true, true, true); } public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), true, true, true); } public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), true, true, true); } @@ -412,9 +412,8 @@ public class MPerm extends Entity implements Prioritized, Registerable, N return accessStatus.hasAccess(); } } - - boolean ret = this.has(mplayer, hostFaction, verboose); - return ret; + + return this.has(mplayer, hostFaction, verboose); } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/Rank.java b/src/com/massivecraft/factions/entity/Rank.java index db6695fe..7c163e75 100644 --- a/src/com/massivecraft/factions/entity/Rank.java +++ b/src/com/massivecraft/factions/entity/Rank.java @@ -3,7 +3,6 @@ package com.massivecraft.factions.entity; import com.massivecraft.massivecore.store.EntityInternal; import com.massivecraft.massivecore.store.EntityInternalMap; import com.massivecraft.massivecore.util.Txt; -import org.apache.commons.lang.ObjectUtils.Null; import org.bukkit.ChatColor; import java.util.Map.Entry; diff --git a/src/com/massivecraft/factions/entity/Vote.java b/src/com/massivecraft/factions/entity/Vote.java index 5aa5aa1e..caa54667 100644 --- a/src/com/massivecraft/factions/entity/Vote.java +++ b/src/com/massivecraft/factions/entity/Vote.java @@ -95,8 +95,7 @@ public class Vote extends EntityInternal implements Named public Faction getFaction() { EntityInternalMap internalMap = (EntityInternalMap) this.getContainer(); - Faction faction = (Faction) internalMap.getEntity(); - return faction; + return (Faction) internalMap.getEntity(); } public void clean() diff --git a/src/com/massivecraft/factions/entity/Warp.java b/src/com/massivecraft/factions/entity/Warp.java index f70d9520..6250d587 100644 --- a/src/com/massivecraft/factions/entity/Warp.java +++ b/src/com/massivecraft/factions/entity/Warp.java @@ -39,8 +39,7 @@ public class Warp extends EntityInternal implements Named public Faction getFaction() { EntityInternalMap internalMap = (EntityInternalMap) this.getContainer(); - Faction faction = (Faction) internalMap.getEntity(); - return faction; + return (Faction) internalMap.getEntity(); } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/event/EventFactionsChunksChange.java b/src/com/massivecraft/factions/event/EventFactionsChunksChange.java index ad8cb003..e4540e0e 100644 --- a/src/com/massivecraft/factions/event/EventFactionsChunksChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsChunksChange.java @@ -10,7 +10,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.event.HandlerList; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; diff --git a/src/com/massivecraft/factions/integration/V18/EngineV18.java b/src/com/massivecraft/factions/integration/V18/EngineV18.java deleted file mode 100644 index 5eefe18b..00000000 --- a/src/com/massivecraft/factions/integration/V18/EngineV18.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.massivecraft.factions.integration.V18; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.engine.EngineCanCombatHappen; -import com.massivecraft.factions.engine.EngineFlagExplosion; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.MassivePlugin; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.Cancellable; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockExplodeEvent; -import org.bukkit.event.entity.AreaEffectCloudApplyEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.projectiles.ProjectileSource; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class EngineV18 extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineV18 i = new EngineV18(); - public static EngineV18 get() { return i; } - - @Override - public MassivePlugin getActivePlugin() - { - return Factions.get(); - } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockExplosion(BlockExplodeEvent event) - { - Location location = event.getBlock().getLocation(); - Cancellable cancellable = event; - Collection blocks = event.blockList(); - - EngineFlagExplosion.get().blockExplosion(location, cancellable, blocks); - } - -} diff --git a/src/com/massivecraft/factions/integration/V18/IntegrationV18.java b/src/com/massivecraft/factions/integration/V18/IntegrationV18.java deleted file mode 100644 index 1534f66e..00000000 --- a/src/com/massivecraft/factions/integration/V18/IntegrationV18.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.massivecraft.factions.integration.V18; - -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.Integration; - -public class IntegrationV18 extends Integration -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationV18 i = new IntegrationV18(); - public static IntegrationV18 get() { return i; } - private IntegrationV18() - { - this.setClassNames( - "org.bukkit.entity.ArmorStand" - ); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Engine getEngine() - { - return EngineV18.get(); - } - -} diff --git a/src/com/massivecraft/factions/integration/lwc/EngineLwc.java b/src/com/massivecraft/factions/integration/lwc/EngineLwc.java index 4ed6c842..5470afdd 100644 --- a/src/com/massivecraft/factions/integration/lwc/EngineLwc.java +++ b/src/com/massivecraft/factions/integration/lwc/EngineLwc.java @@ -123,26 +123,12 @@ public class EngineLwc extends Engine public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction) { - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() - { - @Override - public void run() - { - removeAlienProtectionsRaw(chunkPs, faction); - } - }); + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> removeAlienProtectionsRaw(chunkPs, faction)); } public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction) { - Bukkit.getScheduler().runTaskLater(Factions.get(), new Runnable() - { - @Override - public void run() - { - removeAlienProtectionsAsync(chunkPs, faction); - } - }, 0); + Bukkit.getScheduler().runTaskLater(Factions.get(), () -> removeAlienProtectionsAsync(chunkPs, faction), 0); } } diff --git a/src/com/massivecraft/factions/integration/spigot/EngineSpigot.java b/src/com/massivecraft/factions/integration/spigot/EngineSpigot.java deleted file mode 100644 index fffcaab5..00000000 --- a/src/com/massivecraft/factions/integration/spigot/EngineSpigot.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.massivecraft.factions.integration.spigot; - -import com.massivecraft.factions.engine.EnginePermBuild; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; - -import java.util.List; - - -public class EngineSpigot extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineSpigot i = new EngineSpigot(); - public static EngineSpigot get() { return i; } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - // This is a special Spigot event that fires for Minecraft 1.8 armor stands. - // It also fires for other entity types but for those the event is buggy. - // It seems we can only cancel interaction with armor stands from here. - // Thus we only handle armor stands from here and handle everything else in EngineMain. - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) - { - // Ignore Off Hand - if (isOffHand(event)) return; - - // Gather Info - final Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - final Entity entity = event.getRightClicked(); - final boolean verboose = true; - - // Only care for armor stands. - if (entity.getType() != EntityType.ARMOR_STAND) return; - - // If we can't use, block it - EnginePermBuild.useEntity(player, entity, verboose, event); - } - - /* - * Note: With 1.8 and the slime blocks, retracting and extending pistons - * became more of a problem. Blocks located on the border of a chunk - * could have easily been stolen. That is the reason why every block - * needs to be checked now, whether he moved into a territory which - * he actually may not move into. - */ - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockBuild(BlockPistonExtendEvent event) - { - // Is checking deactivated by MConf? - if ( ! MConf.get().handlePistonProtectionThroughDenyBuild) return; - - Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); - - List blocks = event.getBlocks(); - - // Check for all extended blocks - for (Block block : blocks) - { - // Block which is being pushed into - Block targetBlock = block.getRelative(event.getDirection()); - - // Members of a faction might not have build rights in their own territory, but pistons should still work regardless - Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetBlock)); - if (targetFaction == pistonFaction) continue; - - // Perm check - if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) continue; - - event.setCancelled(true); - return; - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockBuild(BlockPistonRetractEvent event) - { - // Is checking deactivated by MConf? - if ( ! MConf.get().handlePistonProtectionThroughDenyBuild) return; - - Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); - - List blocks = event.getBlocks(); - - // Check for all retracted blocks - for (Block block : blocks) - { - // Is the retracted block air/water/lava? Don't worry about it - if (block.isEmpty() || block.isLiquid()) return; - - // Members of a faction might not have build rights in their own territory, but pistons should still work regardless - Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(block)); - if (targetFaction == pistonFaction) continue; - - // Perm check - if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) continue; - - event.setCancelled(true); - return; - } - } - -} diff --git a/src/com/massivecraft/factions/integration/spigot/IntegrationSpigot.java b/src/com/massivecraft/factions/integration/spigot/IntegrationSpigot.java deleted file mode 100644 index e55ec0a4..00000000 --- a/src/com/massivecraft/factions/integration/spigot/IntegrationSpigot.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.massivecraft.factions.integration.spigot; - -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.Integration; - -public class IntegrationSpigot extends Integration -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationSpigot i = new IntegrationSpigot(); - public static IntegrationSpigot get() { return i; } - private IntegrationSpigot() - { - this.setPredicate(PredicateSpigot.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Engine getEngine() - { - return EngineSpigot.get(); - } - -} diff --git a/src/com/massivecraft/factions/integration/spigot/PredicateSpigot.java b/src/com/massivecraft/factions/integration/spigot/PredicateSpigot.java deleted file mode 100644 index 981a9c52..00000000 --- a/src/com/massivecraft/factions/integration/spigot/PredicateSpigot.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.massivecraft.factions.integration.spigot; - -import com.massivecraft.massivecore.Integration; -import com.massivecraft.massivecore.predicate.Predicate; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; - -public class PredicateSpigot implements Predicate -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static PredicateSpigot i = new PredicateSpigot(); - public static PredicateSpigot get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(Integration integration) - { - try - { - // This line will throw if the class does not exist. - PlayerInteractAtEntityEvent.class.getName(); - - return true; - } - catch (Throwable t) - { - return false; - } - } - -} diff --git a/src/com/massivecraft/factions/util/VisualizeUtil.java b/src/com/massivecraft/factions/util/VisualizeUtil.java index 7cfc0dd2..9fd30dbd 100644 --- a/src/com/massivecraft/factions/util/VisualizeUtil.java +++ b/src/com/massivecraft/factions/util/VisualizeUtil.java @@ -26,13 +26,7 @@ public class VisualizeUtil } public static Set getPlayerLocations(UUID uuid) { - Set ret = playerLocations.get(uuid); - if (ret == null) - { - ret = new HashSet<>(); - playerLocations.put(uuid, ret); - } - return ret; + return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>()); } // -------------------------------------------- //