From 95899e7ab9d25b4e8f9a9e56a7c21b356c12b52e Mon Sep 17 00:00:00 2001 From: Henry Ammermann Date: Tue, 1 Jul 2014 14:51:39 -0700 Subject: [PATCH 1/2] make Flocation's getCircle not use a square root --- src/main/java/com/massivecraft/factions/FLocation.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/massivecraft/factions/FLocation.java b/src/main/java/com/massivecraft/factions/FLocation.java index ee026c7a..c64bb8bf 100644 --- a/src/main/java/com/massivecraft/factions/FLocation.java +++ b/src/main/java/com/massivecraft/factions/FLocation.java @@ -131,10 +131,18 @@ public class FLocation { return Math.sqrt(dx * dx + dz * dz); } + public double getDistanceSquaredTo(FLocation that) { + double dx = that.x - this.x; + double dz = that.z - this.z; + return dx * dx + dz * dz; + } + //----------------------------------------------// // Some Geometry //----------------------------------------------// public Set getCircle(double radius) { + double radiusSquared = radius * radius; + Set ret = new LinkedHashSet(); if (radius <= 0) { return ret; @@ -148,7 +156,7 @@ public class FLocation { for (int x = xfrom; x <= xto; x++) { for (int z = zfrom; z <= zto; z++) { FLocation potential = new FLocation(this.worldName, x, z); - if (this.getDistanceTo(potential) <= radius) { + if (this.getDistanceSquaredTo(potential) <= radiusSquared) { ret.add(potential); } } From 97bc72e4f866cb44c07eb19e87b2c2e482473ab3 Mon Sep 17 00:00:00 2001 From: Henry Ammermann Date: Tue, 1 Jul 2014 23:37:42 -0700 Subject: [PATCH 2/2] intellij autofixes! --- .../com/massivecraft/factions/FPlayer.java | 12 ++----- .../com/massivecraft/factions/Faction.java | 30 ++++------------ .../java/com/massivecraft/factions/P.java | 20 +++-------- .../massivecraft/factions/zcore/MCommand.java | 34 ++++--------------- .../factions/zcore/persist/PlayerEntity.java | 1 - 5 files changed, 18 insertions(+), 79 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index b2024e98..92510094 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -209,7 +209,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { this.autoClaimFor = null; this.autoSafeZoneEnabled = false; this.autoWarZoneEnabled = false; - this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false; + this.loginPvpDisabled = Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0; this.deleteMe = false; this.powerBoost = 0.0; @@ -634,15 +634,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { } public boolean canClaimForFaction(Faction forFaction) { - if (forFaction.isNone()) { - return false; - } - - if (this.isAdminBypassing() || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))) { - return true; - } - - return false; + return !forFaction.isNone() && (this.isAdminBypassing() || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))); } public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) { diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index d8d75551..ae46669f 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -391,25 +391,18 @@ public class Faction extends Entity implements EconomyParticipator { } protected boolean addFPlayer(FPlayer fplayer) { - if (this.isPlayerFreeType()) { - return false; - } + return !this.isPlayerFreeType() && fplayers.add(fplayer); - return fplayers.add(fplayer); } protected boolean removeFPlayer(FPlayer fplayer) { - if (this.isPlayerFreeType()) { - return false; - } + return !this.isPlayerFreeType() && fplayers.remove(fplayer); - return fplayers.remove(fplayer); } public Set getFPlayers() { // return a shallow copy of the FPlayer list, to prevent tampering and concurrency issues - Set ret = new HashSet(fplayers); - return ret; + return new HashSet(fplayers); } public Set getFPlayersWhereOnline(boolean online) { @@ -483,10 +476,7 @@ public class Faction extends Entity implements EconomyParticipator { } // even if all players are technically logged off, maybe someone was on recently enough to not consider them officially offline yet - if (Conf.considerFactionsReallyOfflineAfterXMinutes > 0 && System.currentTimeMillis() < lastPlayerLoggedOffTime + (Conf.considerFactionsReallyOfflineAfterXMinutes * 60000)) { - return true; - } - return false; + return Conf.considerFactionsReallyOfflineAfterXMinutes > 0 && System.currentTimeMillis() < lastPlayerLoggedOffTime + (Conf.considerFactionsReallyOfflineAfterXMinutes * 60000); } public void memberLoggedOff() { @@ -628,11 +618,7 @@ public class Faction extends Entity implements EconomyParticipator { if (ownerData == null) { return false; } - if (ownerData.contains(player.getId())) { - return true; - } - - return false; + return ownerData.contains(player.getId()); } public void setPlayerAsOwner(FPlayer player, FLocation loc) { @@ -691,11 +677,7 @@ public class Faction extends Entity implements EconomyParticipator { Set ownerData = claimOwnership.get(loc); // if no owner list, owner list is empty, or player is in owner list, they're allowed - if (ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId())) { - return true; - } - - return false; + return ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId()); } diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index 0ec205b7..06626acc 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -168,11 +168,8 @@ public class P extends MPlugin { @Override public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly) { - if (sender instanceof Player && FactionsPlayerListener.preventCommand(commandString, (Player) sender)) { - return true; - } + return sender instanceof Player && FactionsPlayerListener.preventCommand(commandString, (Player) sender) || super.handleCommand(sender, commandString, testOnly); - return super.handleCommand(sender, commandString, testOnly); } @Override @@ -206,10 +203,7 @@ public class P extends MPlugin { // enabled or use of the Factions f command without a slash; combination of isPlayerFactionChatting() and isFactionsCommand() public boolean shouldLetFactionsHandleThisChat(AsyncPlayerChatEvent event) { - if (event == null) { - return false; - } - return (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage())); + return event != null && (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage())); } // Does player have Faction Chat enabled? If so, chat plugins should preferably not do channels, @@ -220,10 +214,7 @@ public class P extends MPlugin { } FPlayer me = FPlayers.i.get(player); - if (me == null) { - return false; - } - return me.getChatMode().isAtLeast(ChatMode.ALLIANCE); + return me != null && me.getChatMode().isAtLeast(ChatMode.ALLIANCE); } // Is this chat message actually a Factions command, and thus should be left alone by other plugins? @@ -231,10 +222,7 @@ public class P extends MPlugin { // TODO: GET THIS BACK AND WORKING public boolean isFactionsCommand(String check) { - if (check == null || check.isEmpty()) { - return false; - } - return this.handleCommand(null, check, true); + return !(check == null || check.isEmpty()) && this.handleCommand(null, check, true); } // Get a player's faction tag (faction name), mainly for usage by chat plugins for local/channel chat diff --git a/src/main/java/com/massivecraft/factions/zcore/MCommand.java b/src/main/java/com/massivecraft/factions/zcore/MCommand.java index da125357..11488dac 100644 --- a/src/main/java/com/massivecraft/factions/zcore/MCommand.java +++ b/src/main/java/com/massivecraft/factions/zcore/MCommand.java @@ -138,19 +138,8 @@ public abstract class MCommand { */ // TODO: There should be a boolean for silence public boolean validCall(CommandSender sender, List args) { - if (!validSenderType(sender, true)) { - return false; - } + return validSenderType(sender, true) && validSenderPermissions(sender, true) && validArgs(args, sender); - if (!validSenderPermissions(sender, true)) { - return false; - } - - if (!validArgs(args, sender)) { - return false; - } - - return true; } public boolean isEnabled() { @@ -168,10 +157,7 @@ public abstract class MCommand { } public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) { - if (this.permission == null) { - return true; - } - return p.perm.has(sender, this.permission, informSenderIfNot); + return this.permission == null || p.perm.has(sender, this.permission, informSenderIfNot); } public boolean validArgs(List args, CommandSender sender) { @@ -276,10 +262,7 @@ public abstract class MCommand { // Is set? ====================== public boolean argIsSet(int idx) { - if (this.args.size() < idx + 1) { - return false; - } - return true; + return this.args.size() >= idx + 1; } // STRING ====================== @@ -300,8 +283,7 @@ public abstract class MCommand { return def; } try { - Integer ret = Integer.parseInt(str); - return ret; + return Integer.parseInt(str); } catch (Exception e) { return def; } @@ -321,8 +303,7 @@ public abstract class MCommand { return def; } try { - Double ret = Double.parseDouble(str); - return ret; + return Double.parseDouble(str); } catch (Exception e) { return def; } @@ -340,10 +321,7 @@ public abstract class MCommand { // Boolean ====================== public Boolean strAsBool(String str) { str = str.toLowerCase(); - if (str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1")) { - return true; - } - return false; + return str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1"); } public Boolean argAsBool(int idx, boolean def) { diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntity.java b/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntity.java index 1fb2b4fb..675635b6 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntity.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/PlayerEntity.java @@ -46,5 +46,4 @@ public class PlayerEntity extends Entity { this.sendMessage(msg); } } - }