From e5f864ca6baebf3fd5ef8674a90a2121ed486973 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Thu, 3 Jan 2019 16:26:55 +0100 Subject: [PATCH] Java 8 --- .../factions/cmd/CmdFactionsPermShow.java | 15 ++++++----- .../factions/cmd/CmdFactionsPermView.java | 13 +++++----- .../factions/cmd/CmdFactionsPermViewall.java | 15 +++++------ .../cmd/CmdFactionsRankEditPriority.java | 2 +- .../factions/cmd/CmdFactionsRankList.java | 5 ++-- .../factions/cmd/type/TypeMPermable.java | 7 +++--- .../massivecraft/factions/entity/Faction.java | 25 ++++++++++--------- .../massivecraft/factions/entity/MPerm.java | 4 +-- .../massivecraft/factions/entity/Rank.java | 16 +++++++----- .../migrator/MigratorFaction002Ranks.java | 8 +++--- .../entity/migrator/MigratorMConf004Rank.java | 13 ++++++---- .../migrator/MigratorMPlayer001Ranks.java | 13 ++++++---- 12 files changed, 77 insertions(+), 59 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java index ecb9ebaa..1307360c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.cmd.type.TypeMPerm; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPerm.MPermable; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.entity.Rank; @@ -13,6 +14,8 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.util.Txt; +import java.util.List; +import java.util.Set; import java.util.stream.Collectors; public class CmdFactionsPermShow extends FactionsCommand @@ -39,16 +42,16 @@ public class CmdFactionsPermShow extends FactionsCommand MPerm mperm = this.readArg(); Faction faction = this.readArg(msenderFaction); - var permittedIds = faction.getPerms().get(mperm.getId()); - var permables = new MassiveList(); + Set permittedIds = faction.getPerms().get(mperm.getId()); + List permables = new MassiveList<>(); - for (var permitted : permittedIds) + for (String permitted : permittedIds) { permables.add(idToMPermable(permitted)); } - var removeString = Txt.parse(" of ") + faction.getDisplayName(msender); - var permableList = permables.stream() + String removeString = Txt.parse(" of ") + faction.getDisplayName(msender); + List permableList = permables.stream() .map(permable -> permable.getDisplayName(msender)) .map(s -> s.replace(removeString, "")) .collect(Collectors.toList()); @@ -66,7 +69,7 @@ public class CmdFactionsPermShow extends FactionsCommand Faction faction = Faction.get(id); if (faction != null) return faction; - for (var f : FactionColl.get().getAll()) + for (Faction f : FactionColl.get().getAll()) { Rank rank = f.getRank(id); if (rank != null) return rank; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermView.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermView.java index d1397f74..6b83bf33 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermView.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermView.java @@ -13,6 +13,7 @@ import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; import org.bukkit.ChatColor; +import java.util.List; import java.util.stream.Collectors; public class CmdFactionsPermView extends FactionsCommand @@ -37,7 +38,7 @@ public class CmdFactionsPermView extends FactionsCommand { // Arg: Faction Faction faction = this.readArgAt(1, msenderFaction); - var permableType = TypeMPermable.get(faction); + TypeMPermable permableType = TypeMPermable.get(faction); MPerm.MPermable permable = permableType.read(this.argAt(0), sender); if (permable == faction) @@ -45,9 +46,9 @@ public class CmdFactionsPermView extends FactionsCommand throw new MassiveException().addMsg("A faction can't have perms for itself."); } - var perms = new MassiveList(); + List perms = new MassiveList<>(); - for (var mperm : MPerm.getAll()) + for (MPerm mperm : MPerm.getAll()) { if (faction.isPermitted(permable.getId(), mperm.getId())) perms.add(mperm); } @@ -58,11 +59,11 @@ public class CmdFactionsPermView extends FactionsCommand } else { - var permNames = perms.stream().map(perm -> Txt.parse("") + perm.getName()).collect(Collectors.toList()); + List permNames = perms.stream().map(perm -> Txt.parse("") + perm.getName()).collect(Collectors.toList()); String names = Txt.implodeCommaAnd(permNames, Txt.parse("")); // Create messages - var permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions"; + String permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions"; msg("In %s %s specifically has the %s: %s.", faction.describeTo(msender), permable.getDisplayName(sender), permissionSingularPlural, names); } if (permable instanceof MPlayer) @@ -70,7 +71,7 @@ public class CmdFactionsPermView extends FactionsCommand MPlayer mplayer = (MPlayer) permable; msg("They may have other permissions through their faction membership, rank or relation to %s.", faction.describeTo(msender)); - var msons = new MassiveList(); + List msons = new MassiveList<>(); if (mplayer.getFaction() != faction) msons.add(Mson.parse("[faction]").command(this, mplayer.getFaction().getName(), faction.getName())); msons.add(Mson.parse("[rank]").command(this, mplayer.getFaction().getName() + "-" + mplayer.getRank().getName(), faction.getName())); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java index 53929a4d..cf801a15 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java @@ -11,6 +11,7 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.util.Txt; +import java.util.List; import java.util.stream.Collectors; public class CmdFactionsPermViewall extends FactionsCommand @@ -35,7 +36,7 @@ public class CmdFactionsPermViewall extends FactionsCommand { // Arg: Faction Faction faction = this.readArgAt(1, msenderFaction); - var permableType = TypeMPermable.get(faction); + TypeMPermable permableType = TypeMPermable.get(faction); MPerm.MPermable permable = permableType.read(this.argAt(0), sender); // Self check @@ -45,7 +46,7 @@ public class CmdFactionsPermViewall extends FactionsCommand } // Create list of all applicable permables - var permables = new MassiveList(); + List permables = new MassiveList<>(); permables.add(permable); if (permable instanceof MPlayer) @@ -69,14 +70,14 @@ public class CmdFactionsPermViewall extends FactionsCommand } // Find the perms they have - var perms = new MassiveList(); + List perms = new MassiveList<>(); perm: - for (var mperm : MPerm.getAll()) + for (MPerm mperm : MPerm.getAll()) { String mpermId = mperm.getId(); permable: - for (var mpa : permables) + for (MPermable mpa : permables) { if (!faction.isPermitted(mpa.getId(), mperm.getId())) continue permable; perms.add(mperm); @@ -91,11 +92,11 @@ public class CmdFactionsPermViewall extends FactionsCommand } else { - var permNames = perms.stream().map(perm -> Txt.parse("") + perm.getName()).collect(Collectors.toList()); + List permNames = perms.stream().map(perm -> Txt.parse("") + perm.getName()).collect(Collectors.toList()); String names = Txt.implodeCommaAnd(permNames, Txt.parse("")); // Create messages - var permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions"; + String permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions"; msg("In %s %s has the %s: %s either specifically granted to them or through rank, relation or faction membership.", faction.describeTo(msender), permable.getDisplayName(sender), permissionSingularPlural, names); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java index 4b4ef063..f9823f25 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java @@ -63,7 +63,7 @@ public class CmdFactionsRankEditPriority extends FactionsCommand } } - var priorPriority = rank.getPriority(); + int priorPriority = rank.getPriority(); rank.setPriority(priority); // Visual diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java index 1b8fc91c..9efc5159 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java @@ -9,6 +9,7 @@ import com.massivecraft.massivecore.pager.Pager; import com.massivecraft.massivecore.pager.Stringifier; import java.util.Comparator; +import java.util.List; public class CmdFactionsRankList extends FactionsCommand { @@ -33,10 +34,10 @@ public class CmdFactionsRankList extends FactionsCommand final int page = this.readArg(); Faction faction = this.readArg(msenderFaction); - var ranks = faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority).reversed()); + List ranks = faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority).reversed()); String title = "Rank list for " + faction.describeTo(msender); - var 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/type/TypeMPermable.java b/src/com/massivecraft/factions/cmd/type/TypeMPermable.java index 96ac07bc..8eddd13e 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeMPermable.java +++ b/src/com/massivecraft/factions/cmd/type/TypeMPermable.java @@ -12,6 +12,7 @@ import com.massivecraft.massivecore.command.type.TypeAbstract; import org.bukkit.command.CommandSender; import java.util.Collection; +import java.util.List; import java.util.stream.Collectors; public class TypeMPermable extends TypeAbstract @@ -109,8 +110,8 @@ public class TypeMPermable extends TypeAbstract public Collection getTabList(CommandSender sender, String arg) { - var ret = new MassiveList(); - var faction = this.getFaction(); + List ret = new MassiveList<>(); + Faction faction = this.getFaction(); if (faction == null) faction = MPlayer.get(sender).getFaction(); ret.addAll(faction.getRanks().getAll().stream().map(Rank::getName).collect(Collectors.toList())); ret.addAll(TypeRelation.get().getTabList(sender, arg)); @@ -119,7 +120,7 @@ public class TypeMPermable extends TypeAbstract // Faction specific ranks if (arg.length() >= 2) { - for (var f : FactionColl.get().getAll()) + for (Faction f : FactionColl.get().getAll()) { String name = f.getName(); if (arg.length() <= name.length() && !name.toLowerCase().startsWith(arg.toLowerCase())) continue; diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 9733e201..027960c3 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -36,6 +36,7 @@ import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -757,15 +758,15 @@ public class Faction extends Entity implements FactionsParticipator, MP { Map> ret = new MassiveMap<>(); - var leaderId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("leader")).map(Rank::getId).findFirst(); - var officerId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("officer")).map(Rank::getId).findFirst(); - var memberId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("member")).map(Rank::getId).findFirst(); - var recruitId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("recruit")).map(Rank::getId).findAny(); + Optional leaderId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("leader")).map(Rank::getId).findFirst(); + Optional officerId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("officer")).map(Rank::getId).findFirst(); + Optional memberId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("member")).map(Rank::getId).findFirst(); + Optional recruitId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("recruit")).map(Rank::getId).findAny(); - for (var mperm : MPerm.getAll()) + for (MPerm mperm : MPerm.getAll()) { - var id = mperm.getId(); - var value = new MassiveSet<>(mperm.getStandard()); + String id = mperm.getId(); + MassiveSet value = new MassiveSet<>(mperm.getStandard()); if (value.remove("LEADER") && leaderId.isPresent()) value.add(leaderId.get()); if (value.remove("OFFICER") && officerId.isPresent()) value.add(officerId.get()); @@ -812,7 +813,7 @@ public class Faction extends Entity implements FactionsParticipator, MP public Set getPermitted(String permId) { if (permId == null) throw new NullPointerException("permId"); - var permables = this.perms.get(permId); + Set permables = this.perms.get(permId); if (permables == null) { @@ -837,7 +838,7 @@ public class Faction extends Entity implements FactionsParticipator, MP if (permableId == null) throw new NullPointerException("permableId"); if (permId == null) throw new NullPointerException("permId"); - var permables = this.perms.get(permId); + Set permables = this.perms.get(permId); if (permables == null) { // No perms was found, but likely this is just a new MPerm. @@ -857,7 +858,7 @@ public class Faction extends Entity implements FactionsParticipator, MP { boolean changed = false; - var perms = this.perms.get(permId); + Set perms = this.perms.get(permId); if (perms == null) { // No perms was found, but likely this is just a new MPerm. @@ -889,7 +890,7 @@ public class Faction extends Entity implements FactionsParticipator, MP public void setPermittedRelations(String permId, Collection permables) { - var ids = permables.stream().map(MPerm.MPermable::getId).collect(Collectors.toSet()); + Set ids = permables.stream().map(MPerm.MPermable::getId).collect(Collectors.toSet()); this.getPerms().put(permId, ids); } @@ -1119,7 +1120,7 @@ public class Faction extends Entity implements FactionsParticipator, MP MPlayer oldLeader = this.getLeader(); Rank leaderRank = oldLeader.getRank(); - var replacements = Collections.emptyList(); + List replacements = Collections.emptyList(); for (Rank rank = leaderRank; rank != null; rank = rank.getRankBelow()) { //Skip first diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index 70bc40bf..270f8a59 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -395,7 +395,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N } } - var ret = this.has(mplayer, hostFaction, verboose); + boolean ret = this.has(mplayer, hostFaction, verboose); return ret; } @@ -407,7 +407,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N { if (faction == null) throw new NullPointerException("faction"); - var list = new MassiveList(); + List list = new MassiveList<>(); list.addAll(Arrays.asList(Rel.values())); list.remove(Rel.FACTION); diff --git a/src/com/massivecraft/factions/entity/Rank.java b/src/com/massivecraft/factions/entity/Rank.java index 843fef54..67679395 100644 --- a/src/com/massivecraft/factions/entity/Rank.java +++ b/src/com/massivecraft/factions/entity/Rank.java @@ -5,6 +5,10 @@ import com.massivecraft.massivecore.store.EntityInternalMap; import com.massivecraft.massivecore.util.Txt; import org.bukkit.ChatColor; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; + public class Rank extends EntityInternal implements MPerm.MPermable { // -------------------------------------------- // @@ -22,12 +26,12 @@ public class Rank extends EntityInternal implements MPerm.MPermable @Override public void preDetach(String id) { - for (var f : FactionColl.get().getAll()) + for (Faction f : FactionColl.get().getAll()) { - for (var it = f.getPerms().entrySet().iterator(); it.hasNext();) + for (Iterator>> it = f.getPerms().entrySet().iterator(); it.hasNext();) { - var entry = it.next(); - var value = entry.getValue(); + Entry> entry = it.next(); + Set value = entry.getValue(); value.remove(id); } } @@ -51,8 +55,8 @@ public class Rank extends EntityInternal implements MPerm.MPermable public Faction getFaction() { - var internalMap = (EntityInternalMap) this.getContainer(); - var faction = (Faction) internalMap.getEntity(); + EntityInternalMap internalMap = (EntityInternalMap) this.getContainer(); + Faction faction = (Faction) internalMap.getEntity(); return faction; } diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java index ecfd24c9..d29c146c 100644 --- a/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java +++ b/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java @@ -52,14 +52,14 @@ public class MigratorFaction002Ranks extends MigratorRoot map.put(idMember, member); map.put(idRecruit, recruit); - var jsonMap = MassiveCore.gson.toJsonTree(map, (new TypeToken>(){}).getType()); + JsonElement jsonMap = MassiveCore.gson.toJsonTree(map, (new TypeToken>(){}).getType()); entity.add("ranks", jsonMap); - var priorPerms = entity.get("perms"); - var newPerms = getPerms(priorPerms, idLeader, idOfficer, idMember, idRecruit); + JsonElement priorPerms = entity.get("perms"); + Map> newPerms = getPerms(priorPerms, idLeader, idOfficer, idMember, idRecruit); - var jsonPerms = MassiveCore.gson.toJsonTree(newPerms, (new TypeToken>>(){}).getType()); + JsonElement jsonPerms = MassiveCore.gson.toJsonTree(newPerms, (new TypeToken>>(){}).getType()); entity.add("perms", jsonPerms); } diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java b/src/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java index 187a68b1..1625d7d3 100644 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java +++ b/src/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java @@ -1,10 +1,13 @@ package com.massivecraft.factions.entity.migrator; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.massivecraft.factions.entity.MConf; import com.massivecraft.massivecore.store.migrator.MigratorRoot; +import java.util.Iterator; + public class MigratorMConf004Rank extends MigratorRoot { // -------------------------------------------- // @@ -56,17 +59,17 @@ public class MigratorMConf004Rank extends MigratorRoot JsonObject map = element.getAsJsonObject(); if (map.has("MEMBER")) { - var e = map.remove("MEMBER"); + JsonElement e = map.remove("MEMBER"); map.add("FACTION", e); } } if (element.isJsonArray()) { - var array = element.getAsJsonArray(); - var success = false; - for (var it = array.iterator(); it.hasNext(); ) + JsonArray array = element.getAsJsonArray(); + boolean success = false; + for (Iterator it = array.iterator(); it.hasNext(); ) { - var e = it.next(); + JsonElement e = it.next(); if (!e.getAsString().equals("MEMBER")) continue; it.remove(); success = true; diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java b/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java index f008dfff..431ab9a8 100644 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java +++ b/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java @@ -4,8 +4,11 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; import com.massivecraft.massivecore.store.migrator.MigratorRoot; +import java.util.Collection; + public class MigratorMPlayer001Ranks extends MigratorRoot { // -------------------------------------------- // @@ -26,12 +29,12 @@ public class MigratorMPlayer001Ranks extends MigratorRoot @Override public void migrateInner(JsonObject entity) { - var role = entity.remove("role").getAsString(); - var factionId = entity.get("factionId").getAsString(); - var faction = Faction.get(factionId); + String role = entity.remove("role").getAsString(); + String factionId = entity.get("factionId").getAsString(); + Faction faction = Faction.get(factionId); - var ranks = faction.getRanks().getAll(); - for (var rank : ranks) + Collection ranks = faction.getRanks().getAll(); + for (Rank rank : ranks) { if (!rank.getName().equalsIgnoreCase(role)) continue;