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>
<execution>
<phase>package</phase>
<goals><goal>proguard</goal></goals>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
@ -103,7 +105,7 @@
<!-- 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>-keepclassmembers enum * { *; } </option>
<option>-keepclassmembers enum * { *; }</option>
<option>-keep class com.massivecraft.factions.zcore.persist.json.** { *; }</option>
<!-- keep the lib -->

View File

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

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import java.io.Serializable;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
public class FLocation implements Serializable {
@ -251,6 +252,6 @@ public class FLocation implements Serializable {
}
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();
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() {
switch (Conf.backEnd) {
case JSON:
if (Conf.backEnd == Conf.Backend.JSON) {
return new JSONFPlayers();
}
return null;

View File

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

View File

@ -79,9 +79,7 @@ public class CmdHome extends FCommand {
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 (Conf.homesTeleportAllowedEnemyDistance > 0 &&
!faction.isSafeZone() &&
(!fme.isInOwnTerritory() || (fme.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) {
if (Conf.homesTeleportAllowedEnemyDistance > 0 && !faction.isSafeZone() && (!fme.isInOwnTerritory() || !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)) {
World w = loc.getWorld();
double x = loc.getX();
double y = loc.getY();

View File

@ -69,7 +69,7 @@ public class CmdList extends FCommand {
});
// 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 f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) {

View File

@ -67,7 +67,7 @@ public class CmdRules extends FCommand {
String message = "";
StringBuilder string = new StringBuilder(message);
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.msg(TL.COMMAND_RULES_ADD_SUCCESS);

View File

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

View File

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

View File

@ -496,7 +496,6 @@ public class FactionsBlockListener implements Listener {
Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
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
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
blockList.remove();
}
}
event.blockList().removeIf(block -> !this.checkExplosionForBlock(boomer, block));
// Cancel the event if no block will explode
if (!event.blockList().isEmpty() && (boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart) && Conf.handleExploitTNTWaterlog) {
@ -302,10 +295,7 @@ public class FactionsEntityListener implements Listener {
return false;
} 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
(boomer instanceof Fireball || boomer instanceof WitherSkull || 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())) {
(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())) {
// ghast fireball which needs prevention
return false;
} 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
//iterate through all of recipients and check if they're muted, then remove them from the event list
List<Player> l = new ArrayList<>();
l.addAll(e.getRecipients());
List<Player> l = new ArrayList<>(e.getRecipients());
for (int i = l.size() - 1; i >= 0; i--){ // going backwards in the list to prevent a ConcurrentModificationException
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 java.util.List;
import java.util.Objects;
public abstract class FSidebarProvider {
@ -24,7 +25,7 @@ public abstract class FSidebarProvider {
// Run through Placeholder API first
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) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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