Java 8
This commit is contained in:
@ -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<Faction> implements FactionsParticipator, MP
|
||||
{
|
||||
Map<String, Set<String>> 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<String> leaderId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("leader")).map(Rank::getId).findFirst();
|
||||
Optional<String> officerId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("officer")).map(Rank::getId).findFirst();
|
||||
Optional<String> memberId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("member")).map(Rank::getId).findFirst();
|
||||
Optional<String> 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<String> 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<Faction> implements FactionsParticipator, MP
|
||||
public Set<String> getPermitted(String permId)
|
||||
{
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
var permables = this.perms.get(permId);
|
||||
Set<String> permables = this.perms.get(permId);
|
||||
|
||||
if (permables == null)
|
||||
{
|
||||
@ -837,7 +838,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
if (permableId == null) throw new NullPointerException("permableId");
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
|
||||
var permables = this.perms.get(permId);
|
||||
Set<String> 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<Faction> implements FactionsParticipator, MP
|
||||
{
|
||||
boolean changed = false;
|
||||
|
||||
var perms = this.perms.get(permId);
|
||||
Set<String> 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<Faction> implements FactionsParticipator, MP
|
||||
|
||||
public void setPermittedRelations(String permId, Collection<MPerm.MPermable> permables)
|
||||
{
|
||||
var ids = permables.stream().map(MPerm.MPermable::getId).collect(Collectors.toSet());
|
||||
Set<String> ids = permables.stream().map(MPerm.MPermable::getId).collect(Collectors.toSet());
|
||||
this.getPerms().put(permId, ids);
|
||||
}
|
||||
|
||||
@ -1119,7 +1120,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
MPlayer oldLeader = this.getLeader();
|
||||
Rank leaderRank = oldLeader.getRank();
|
||||
|
||||
var replacements = Collections.<MPlayer>emptyList();
|
||||
List<MPlayer> replacements = Collections.<MPlayer>emptyList();
|
||||
for (Rank rank = leaderRank; rank != null; rank = rank.getRankBelow())
|
||||
{
|
||||
//Skip first
|
||||
|
@ -395,7 +395,7 @@ public class MPerm extends Entity<MPerm> 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<MPerm> implements Prioritized, Registerable, N
|
||||
{
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
var list = new MassiveList<MPermable>();
|
||||
List<MPermable> list = new MassiveList<>();
|
||||
|
||||
list.addAll(Arrays.asList(Rel.values()));
|
||||
list.remove(Rel.FACTION);
|
||||
|
@ -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<Rank> implements MPerm.MPermable
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -22,12 +26,12 @@ public class Rank extends EntityInternal<Rank> 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<Entry<String, Set<String>>> it = f.getPerms().entrySet().iterator(); it.hasNext();)
|
||||
{
|
||||
var entry = it.next();
|
||||
var value = entry.getValue();
|
||||
Entry<String, Set<String>> entry = it.next();
|
||||
Set<String> value = entry.getValue();
|
||||
value.remove(id);
|
||||
}
|
||||
}
|
||||
@ -51,8 +55,8 @@ public class Rank extends EntityInternal<Rank> implements MPerm.MPermable
|
||||
|
||||
public Faction getFaction()
|
||||
{
|
||||
var internalMap = (EntityInternalMap<Rank>) this.getContainer();
|
||||
var faction = (Faction) internalMap.getEntity();
|
||||
EntityInternalMap<Rank> internalMap = (EntityInternalMap<Rank>) this.getContainer();
|
||||
Faction faction = (Faction) internalMap.getEntity();
|
||||
return faction;
|
||||
}
|
||||
|
||||
|
@ -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<Map<String,Rank>>(){}).getType());
|
||||
JsonElement jsonMap = MassiveCore.gson.toJsonTree(map, (new TypeToken<Map<String,Rank>>(){}).getType());
|
||||
entity.add("ranks", jsonMap);
|
||||
|
||||
|
||||
var priorPerms = entity.get("perms");
|
||||
var newPerms = getPerms(priorPerms, idLeader, idOfficer, idMember, idRecruit);
|
||||
JsonElement priorPerms = entity.get("perms");
|
||||
Map<String, Set<String>> newPerms = getPerms(priorPerms, idLeader, idOfficer, idMember, idRecruit);
|
||||
|
||||
var jsonPerms = MassiveCore.gson.toJsonTree(newPerms, (new TypeToken<Map<String,Set<String>>>(){}).getType());
|
||||
JsonElement jsonPerms = MassiveCore.gson.toJsonTree(newPerms, (new TypeToken<Map<String,Set<String>>>(){}).getType());
|
||||
entity.add("perms", jsonPerms);
|
||||
}
|
||||
|
||||
|
@ -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<JsonElement> it = array.iterator(); it.hasNext(); )
|
||||
{
|
||||
var e = it.next();
|
||||
JsonElement e = it.next();
|
||||
if (!e.getAsString().equals("MEMBER")) continue;
|
||||
it.remove();
|
||||
success = true;
|
||||
|
@ -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<Rank> ranks = faction.getRanks().getAll();
|
||||
for (Rank rank : ranks)
|
||||
{
|
||||
if (!rank.getName().equalsIgnoreCase(role)) continue;
|
||||
|
||||
|
Reference in New Issue
Block a user