Code Enhancements...

This commit is contained in:
Driftay 2019-07-03 23:24:32 -04:00
parent 2937e05fda
commit 9d40fec03b
23 changed files with 55 additions and 98 deletions

View File

@ -83,7 +83,9 @@
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
<goals><goal>proguard</goal></goals> <goals>
<goal>proguard</goal>
</goals>
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
@ -103,7 +105,7 @@
<!-- These three are required for the json serializer, breaks if removed, oh and also for the config :) --> <!-- These three are required for the json serializer, breaks if removed, oh and also for the config :) -->
<option>-keep class com.massivecraft.factions.Conf { *; }</option> <option>-keep class com.massivecraft.factions.Conf { *; }</option>
<option>-keepclassmembers enum * { *; } </option> <option>-keepclassmembers enum * { *; }</option>
<option>-keep class com.massivecraft.factions.zcore.persist.json.** { *; }</option> <option>-keep class com.massivecraft.factions.zcore.persist.json.** { *; }</option>
<!-- keep the lib --> <!-- keep the lib -->

View File

@ -21,7 +21,6 @@ public class Conf {
public static final transient boolean DYNMAP_STYLE_BOOST = false; public static final transient boolean DYNMAP_STYLE_BOOST = false;
public static List<String> baseCommandAliases = new ArrayList<>(); public static List<String> baseCommandAliases = new ArrayList<>();
public static boolean allowNoSlashCommand = true; public static boolean allowNoSlashCommand = true;
public static Set<String> allowedStealthFactions = new LinkedHashSet<>();
// Colors // Colors
public static ChatColor colorMember = ChatColor.GREEN; public static ChatColor colorMember = ChatColor.GREEN;

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
public class FLocation implements Serializable { public class FLocation implements Serializable {
@ -251,6 +252,6 @@ public class FLocation implements Serializable {
} }
FLocation that = (FLocation) obj; FLocation that = (FLocation) obj;
return this.x == that.x && this.z == that.z && (this.worldName == null ? that.worldName == null : this.worldName.equals(that.worldName)); return this.x == that.x && this.z == that.z && (Objects.equals(this.worldName, that.worldName));
} }
} }

View File

@ -367,11 +367,11 @@ public interface FPlayer extends EconomyParticipator {
boolean checkIfNearbyEnemies(); boolean checkIfNearbyEnemies();
public int getCooldown(String cmd); int getCooldown(String cmd);
public void setCooldown(String cmd, long cooldown); void setCooldown(String cmd, long cooldown);
public boolean isCooldownEnded(String cmd); boolean isCooldownEnded(String cmd);
// ------------------------------- // -------------------------------

View File

@ -14,8 +14,7 @@ public abstract class FPlayers {
} }
private static FPlayers getFPlayersImpl() { private static FPlayers getFPlayersImpl() {
switch (Conf.backEnd) { if (Conf.backEnd == Conf.Backend.JSON) {
case JSON:
return new JSONFPlayers(); return new JSONFPlayers();
} }
return null; return null;

View File

@ -27,14 +27,11 @@ public class CmdConvert extends FCommand {
this.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_RUNNING.toString()); this.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_RUNNING.toString());
return; return;
} }
switch (nb) { if (nb == Backend.JSON) {
case JSON:
FactionsJSON.convertTo(); FactionsJSON.convertTo();
break; } else {
default:
this.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_INVALID.toString()); this.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_INVALID.toString());
return; return;
} }
Conf.backEnd = nb; Conf.backEnd = nb;
} }

View File

@ -79,9 +79,7 @@ public class CmdHome extends FCommand {
final Location loc = me.getLocation().clone(); final Location loc = me.getLocation().clone();
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
if (Conf.homesTeleportAllowedEnemyDistance > 0 && if (Conf.homesTeleportAllowedEnemyDistance > 0 && !faction.isSafeZone() && (!fme.isInOwnTerritory() || !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)) {
!faction.isSafeZone() &&
(!fme.isInOwnTerritory() || (fme.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) {
World w = loc.getWorld(); World w = loc.getWorld();
double x = loc.getX(); double x = loc.getX();
double y = loc.getY(); double y = loc.getY();

View File

@ -69,7 +69,7 @@ public class CmdList extends FCommand {
}); });
// Then sort by how many members are online now // Then sort by how many members are online now
Collections.sort(factionList, (f1, f2) -> { factionList.sort((f1, f2) -> {
int f1Size = f1.getFPlayersWhereOnline(true).size(); int f1Size = f1.getFPlayersWhereOnline(true).size();
int f2Size = f2.getFPlayersWhereOnline(true).size(); int f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) { if (f1Size < f2Size) {

View File

@ -67,7 +67,7 @@ public class CmdRules extends FCommand {
String message = ""; String message = "";
StringBuilder string = new StringBuilder(message); StringBuilder string = new StringBuilder(message);
for (int i = 1; i <= args.size() - 1; i++) { for (int i = 1; i <= args.size() - 1; i++) {
string.append(" " + args.get(i)); string.append(" ").append(args.get(i));
} }
fme.getFaction().addRule(string.toString()); fme.getFaction().addRule(string.toString());
fme.msg(TL.COMMAND_RULES_ADD_SUCCESS); fme.msg(TL.COMMAND_RULES_ADD_SUCCESS);

View File

@ -72,9 +72,7 @@ public class CmdSeeChunk extends FCommand {
private void startTask() { private void startTask() {
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(SaberFactions.plugin, () -> { taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(SaberFactions.plugin, () -> {
Iterator<String> itr = seeChunkMap.keySet().iterator(); for (Object nameObject : seeChunkMap.keySet()) {
while (itr.hasNext()) {
Object nameObject = itr.next();
String name = nameObject + ""; String name = nameObject + "";
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
showBorders(player); showBorders(player);

View File

@ -43,6 +43,8 @@ public class CmdStrikeSet extends FCommand {
if (faction == null) { if (faction == null) {
fme.msg(TL.COMMAND_SETSTRIKES_FAILURE.toString().replace("{faction}", args.get(1))); fme.msg(TL.COMMAND_SETSTRIKES_FAILURE.toString().replace("{faction}", args.get(1)));
} }
if (faction != null) {
if (args.get(0).equalsIgnoreCase("set")) { if (args.get(0).equalsIgnoreCase("set")) {
faction.setStrikes(argAsInt(2)); faction.setStrikes(argAsInt(2));
success = true; success = true;
@ -64,6 +66,7 @@ public class CmdStrikeSet extends FCommand {
.replace("{strikes}", faction.getStrikes() + "")); .replace("{strikes}", faction.getStrikes() + ""));
} }
} }
}
private String getReason() { private String getReason() {
String reason = ""; String reason = "";

View File

@ -496,7 +496,6 @@ public class FactionsBlockListener implements Listener {
Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER); Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners"); fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners");
return;
} }
} }
} }

View File

@ -244,16 +244,9 @@ public class FactionsEntityListener implements Listener {
} }
// Loop the blocklist to run checks on each aimed block // Loop the blocklist to run checks on each aimed block
Iterator<Block> blockList = event.blockList().iterator();
while (blockList.hasNext()) {
Block block = blockList.next();
if (!this.checkExplosionForBlock(boomer, block)) {
// The block don't have to explode // The block don't have to explode
blockList.remove(); event.blockList().removeIf(block -> !this.checkExplosionForBlock(boomer, block));
}
}
// Cancel the event if no block will explode // Cancel the event if no block will explode
if (!event.blockList().isEmpty() && (boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart) && Conf.handleExploitTNTWaterlog) { if (!event.blockList().isEmpty() && (boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart) && Conf.handleExploitTNTWaterlog) {
@ -302,10 +295,7 @@ public class FactionsEntityListener implements Listener {
return false; return false;
} else if ( } else if (
// it's a bit crude just using fireball protection for Wither boss too, but I'd rather not add in a whole new set of xxxBlockWitherExplosion or whatever // it's a bit crude just using fireball protection for Wither boss too, but I'd rather not add in a whole new set of xxxBlockWitherExplosion or whatever
(boomer instanceof Fireball || boomer instanceof WitherSkull || boomer instanceof Wither) && ((faction.isWilderness() && Conf.wildernessBlockFireballs && !Conf.worldsNoWildernessProtection.contains(block.getWorld().getName())) || (boomer instanceof Fireball || boomer instanceof Wither) && (faction.isWilderness() && Conf.wildernessBlockFireballs && !Conf.worldsNoWildernessProtection.contains(block.getWorld().getName()) || faction.isNormal() && (online ? Conf.territoryBlockFireballs : Conf.territoryBlockFireballsWhenOffline) || faction.isWarZone() && Conf.warZoneBlockFireballs || faction.isSafeZone())) {
(faction.isNormal() && (online ? Conf.territoryBlockFireballs : Conf.territoryBlockFireballsWhenOffline)) ||
(faction.isWarZone() && Conf.warZoneBlockFireballs) ||
faction.isSafeZone())) {
// ghast fireball which needs prevention // ghast fireball which needs prevention
return false; return false;
} else } else

View File

@ -992,9 +992,7 @@ public class FactionsPlayerListener implements Listener {
//we made it this far, since we didn't return yet, we must have sent the chat event through //we made it this far, since we didn't return yet, we must have sent the chat event through
//iterate through all of recipients and check if they're muted, then remove them from the event list //iterate through all of recipients and check if they're muted, then remove them from the event list
List<Player> l = new ArrayList<>(); List<Player> l = new ArrayList<>(e.getRecipients());
l.addAll(e.getRecipients());
for (int i = l.size() - 1; i >= 0; i--){ // going backwards in the list to prevent a ConcurrentModificationException for (int i = l.size() - 1; i >= 0; i--){ // going backwards in the list to prevent a ConcurrentModificationException
Player recipient = l.get(i); Player recipient = l.get(i);

View File

@ -7,6 +7,7 @@ import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagUtil; import com.massivecraft.factions.zcore.util.TagUtil;
import java.util.List; import java.util.List;
import java.util.Objects;
public abstract class FSidebarProvider { public abstract class FSidebarProvider {
@ -24,7 +25,7 @@ public abstract class FSidebarProvider {
// Run through Placeholder API first // Run through Placeholder API first
s = TagUtil.parsePlaceholders(fPlayer.getPlayer(), s); s = TagUtil.parsePlaceholders(fPlayer.getPlayer(), s);
return qualityAssure(TagUtil.parsePlain(faction, fPlayer, s)); return qualityAssure(Objects.requireNonNull(TagUtil.parsePlain(faction, fPlayer, s)));
} }
private String qualityAssure(String line) { private String qualityAssure(String line) {

View File

@ -51,5 +51,4 @@ public class PlayerChunkLocationExpression extends SimpleExpression<String> {
} }
return null; return null;
} }
} }

View File

@ -40,9 +40,7 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLoca
nameSet = new HashSet<>(); nameSet = new HashSet<>();
iter = entry2.getValue().getAsJsonArray().iterator(); iter = entry2.getValue().getAsJsonArray().iterator();
while (iter.hasNext()) { while (iter.hasNext()) nameSet.add(iter.next().getAsString());
nameSet.add(iter.next().getAsString());
}
locationMap.put(new FLocation(worldName, x, z), nameSet); locationMap.put(new FLocation(worldName, x, z), nameSet);
} }

View File

@ -16,11 +16,7 @@ public class VisualizeUtil {
} }
public static Set<Location> getPlayerLocations(UUID uuid) { public static Set<Location> getPlayerLocations(UUID uuid) {
Set<Location> ret = playerLocations.get(uuid); Set<Location> ret = playerLocations.computeIfAbsent(uuid, k -> new HashSet<>());
if (ret == null) {
ret = new HashSet<>();
playerLocations.put(uuid, ret);
}
return ret; return ret;
} }

View File

@ -16,7 +16,7 @@ public class EXPUpgrade implements Listener {
public void onDeath(EntityDeathEvent e) { public void onDeath(EntityDeathEvent e) {
Entity killer = e.getEntity().getKiller(); Entity killer = e.getEntity().getKiller();
if (killer == null || !(killer instanceof Player)) if (killer == null)
return; return;
FLocation floc = new FLocation(e.getEntity().getLocation()); FLocation floc = new FLocation(e.getEntity().getLocation());

View File

@ -22,10 +22,8 @@ public class RedstoneUpgrade implements Listener {
if (!factionAtLoc.isWilderness()) { if (!factionAtLoc.isWilderness()) {
int level = factionAtLoc.getUpgrade(UpgradeType.REDSTONE); int level = factionAtLoc.getUpgrade(UpgradeType.REDSTONE);
if (level != 0) { if (level != 0) {
switch (level) { if (level == 1) {
case 1:
SaberFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Redstone.Cost"); SaberFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Redstone.Cost");
break;
} }
if (unbreakable.contains(block)) { if (unbreakable.contains(block)) {
e.setCancelled(true); e.setCancelled(true);

View File

@ -53,12 +53,7 @@ public abstract class MemoryBoard extends Board {
public void removeAt(FLocation flocation) { public void removeAt(FLocation flocation) {
Faction faction = getFactionAt(flocation); Faction faction = getFactionAt(flocation);
Iterator<LazyLocation> it = faction.getWarps().values().iterator(); faction.getWarps().values().removeIf(lazyLocation -> flocation.isInChunk(lazyLocation.getLocation()));
while (it.hasNext()) {
if (flocation.isInChunk(it.next().getLocation())) {
it.remove();
}
}
clearOwnershipAt(flocation); clearOwnershipAt(flocation);
flocationIds.remove(flocation); flocationIds.remove(flocation);
} }

View File

@ -273,12 +273,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
} }
public void unban(FPlayer player) { public void unban(FPlayer player) {
Iterator<BanInfo> iter = bans.iterator(); bans.removeIf(banInfo -> banInfo.getBanned().equalsIgnoreCase(player.getId()));
while (iter.hasNext()) {
if (iter.next().getBanned().equalsIgnoreCase(player.getId())) {
iter.remove();
}
}
} }
@Override @Override
@ -1199,12 +1194,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
continue; continue;
} }
Iterator<String> iter = ownerData.iterator(); ownerData.removeIf(s -> s.equals(player.getId()));
while (iter.hasNext()) {
if (iter.next().equals(player.getId())) {
iter.remove();
}
}
if (ownerData.isEmpty()) { if (ownerData.isEmpty()) {
claimOwnership.remove(entry.getKey()); claimOwnership.remove(entry.getKey());

View File

@ -9,10 +9,6 @@ commands:
factions: factions:
description: Reference command for Factions. description: Reference command for Factions.
aliases: [f] aliases: [f]
bottle:
description: withdraw experience.
withdraw:
description: withdraw money.
permissions: permissions:
factions.kit.admin: factions.kit.admin:
description: All faction permissions. description: All faction permissions.