From b8c695c2f48d5dd2565d3eafd097d9363f6fce8c Mon Sep 17 00:00:00 2001 From: Driftay Date: Thu, 7 May 2020 05:11:28 -0400 Subject: [PATCH] Grace Check in checkForExplosion Method & Added a Async Task On Show. NOTE: Ran 100 Alts Running /f who every second whilst all being in my faction with 0 lag or errors with LuckPerms --- .../massivecraft/factions/FactionsPlugin.java | 2 +- .../massivecraft/factions/cmd/CmdShow.java | 54 ++++++++++--------- .../listeners/FactionsEntityListener.java | 3 ++ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/FactionsPlugin.java b/src/main/java/com/massivecraft/factions/FactionsPlugin.java index 0e1485a2..cc9be833 100755 --- a/src/main/java/com/massivecraft/factions/FactionsPlugin.java +++ b/src/main/java/com/massivecraft/factions/FactionsPlugin.java @@ -585,7 +585,7 @@ public class FactionsPlugin extends MPlugin { public String getPrimaryGroup(OfflinePlayer player) { - return (perms == null || !perms.hasGroupSupport()) ? " " : perms.getPrimaryGroup(Bukkit.getWorlds().get(0).toString(), player); + return perms == null || !perms.hasGroupSupport() ? " " : perms.getPrimaryGroup(Bukkit.getWorlds().get(0).toString(), player); } public TimerManager getTimerManager() { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java index b87e0242..ce7354a6 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java @@ -78,34 +78,38 @@ public class CmdShow extends FCommand { return; // we only show header for non-normal factions } - for (String raw : show) { - String parsed = TagUtil.parsePlain(faction, context.fPlayer, raw); // use relations - if (parsed == null) { - continue; // Due to minimal f show. - } - - if (context.fPlayer != null) { - parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed); - } - - if (TagUtil.hasFancy(parsed)) { - List fancy = TagUtil.parseFancy(faction, context.fPlayer, parsed); - if (fancy != null) - context.sendFancyMessage(fancy); - - continue; - } - if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) { - if (parsed.contains("{ig}")) { - // replaces all variables with no home TL - parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString(); + List finalShow = show; + Faction finalFaction = faction; + FactionsPlugin.getInstance().getServer().getScheduler().runTaskAsynchronously(FactionsPlugin.instance, () -> { + for (String raw : finalShow) { + String parsed = TagUtil.parsePlain(finalFaction, context.fPlayer, raw); // use relations + if (parsed == null) { + continue; // Due to minimal f show. } - if (parsed.contains("%")) { - parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. + + if (context.fPlayer != null) { + parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed); + } + + if (TagUtil.hasFancy(parsed)) { + List fancy = TagUtil.parseFancy(finalFaction, context.fPlayer, parsed); + if (fancy != null) + context.sendFancyMessage(fancy); + + continue; + } + if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) { + if (parsed.contains("{ig}")) { + // replaces all variables with no home TL + parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString(); + } + if (parsed.contains("%")) { + parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. + } + context.msg(FactionsPlugin.getInstance().txt.parse(parsed)); } - context.msg(FactionsPlugin.getInstance().txt.parse(parsed)); } - } + }); } @Override diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java index cce2e784..f9f25d3b 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.event.PowerLossEvent; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.MiscUtil; +import com.massivecraft.factions.util.timer.type.GraceTimer; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -258,6 +259,8 @@ public class FactionsEntityListener implements Listener { private boolean checkExplosionForBlock(Entity boomer, Block block) { Faction faction = Board.getInstance().getFactionAt(new FLocation(block.getLocation())); + if(FactionsPlugin.getInstance().getTimerManager().graceTimer.getRemaining() > 0) return false; + if (faction.noExplosionsInTerritory() || (faction.isPeaceful() && Conf.peacefulTerritoryDisableBoom)) return false; // faction is peaceful and has explosions set to disabled