From 663bd96d267f9fb0aa9dd6e5491c84b152d645d3 Mon Sep 17 00:00:00 2001 From: Driftay Date: Thu, 2 Apr 2020 08:33:33 -0400 Subject: [PATCH] Proper Distribution to Vankka For Proper Discord Code & Fixed F Leader Leaving Faction Disband Message --- .../massivecraft/factions/cmd/Aliases.java | 1 + .../massivecraft/factions/cmd/CmdDiscord.java | 4 ++ .../factions/discord/CmdInviteBot.java | 2 +- .../factions/discord/CmdSetGuild.java | 2 +- .../factions/discord/Discord.java | 4 ++ .../factions/discord/DiscordListener.java | 2 +- .../factions/discord/DiscordSetupAttempt.java | 5 ++ .../factions/discord/FactionChatHandler.java | 5 ++ .../factions/integration/Worldguard.java | 41 ++++++++++++- .../listeners/FactionsBlockListener.java | 58 +++++++++---------- .../factions/shop/ShopGUIFrame.java | 3 +- .../factions/zcore/persist/MemoryFPlayer.java | 7 ++- .../massivecraft/factions/zcore/util/TL.java | 5 ++ 13 files changed, 100 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/Aliases.java b/src/main/java/com/massivecraft/factions/cmd/Aliases.java index 806bd1ef..e7c3ff2a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/Aliases.java +++ b/src/main/java/com/massivecraft/factions/cmd/Aliases.java @@ -38,6 +38,7 @@ public class Aliases { public static ArrayList money_withdraw = new ArrayList<>(Arrays.asList("w", "withdraw")); public static ArrayList grace = new ArrayList<>(Collections.singletonList("grace")); public static ArrayList logout = new ArrayList<>(Collections.singletonList("logout")); + public static ArrayList points_balance = new ArrayList<>(Arrays.asList("balance", "bal")); public static ArrayList points_points = new ArrayList<>(Collections.singletonList("points")); public static ArrayList points_add = new ArrayList<>(Collections.singletonList("add")); public static ArrayList points_remove = new ArrayList<>(Collections.singletonList("remove")); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDiscord.java b/src/main/java/com/massivecraft/factions/cmd/CmdDiscord.java index 33fd4a58..81184a72 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDiscord.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDiscord.java @@ -6,6 +6,10 @@ import com.massivecraft.factions.zcore.util.TL; import java.util.Random; +/** + * @author SaberTeam + */ + public class CmdDiscord extends FCommand { public CmdDiscord() { super(); diff --git a/src/main/java/com/massivecraft/factions/discord/CmdInviteBot.java b/src/main/java/com/massivecraft/factions/discord/CmdInviteBot.java index d89fb2f3..f4135f5f 100644 --- a/src/main/java/com/massivecraft/factions/discord/CmdInviteBot.java +++ b/src/main/java/com/massivecraft/factions/discord/CmdInviteBot.java @@ -11,7 +11,7 @@ import net.dv8tion.jda.core.Permission; public class CmdInviteBot extends FCommand { /** - * @author Driftay + * @author Vankka */ public CmdInviteBot() { diff --git a/src/main/java/com/massivecraft/factions/discord/CmdSetGuild.java b/src/main/java/com/massivecraft/factions/discord/CmdSetGuild.java index 1477b6de..72decd19 100644 --- a/src/main/java/com/massivecraft/factions/discord/CmdSetGuild.java +++ b/src/main/java/com/massivecraft/factions/discord/CmdSetGuild.java @@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit; public class CmdSetGuild extends FCommand { /** - * @author Driftay + * @author Vankka */ private EventWaiter eventWaiter; diff --git a/src/main/java/com/massivecraft/factions/discord/Discord.java b/src/main/java/com/massivecraft/factions/discord/Discord.java index b0d83e82..a8dafb03 100644 --- a/src/main/java/com/massivecraft/factions/discord/Discord.java +++ b/src/main/java/com/massivecraft/factions/discord/Discord.java @@ -18,6 +18,10 @@ import java.util.HashSet; import java.util.Objects; import java.util.logging.Level; +/** + * @author SaberTeam + */ + public class Discord { //We dont want waitingLink to reset during reload so we are going to set it here public static HashMap waitingLink; diff --git a/src/main/java/com/massivecraft/factions/discord/DiscordListener.java b/src/main/java/com/massivecraft/factions/discord/DiscordListener.java index 40592a8b..0375bec0 100644 --- a/src/main/java/com/massivecraft/factions/discord/DiscordListener.java +++ b/src/main/java/com/massivecraft/factions/discord/DiscordListener.java @@ -25,7 +25,7 @@ import java.util.stream.Collectors; public class DiscordListener extends ListenerAdapter { /** - * @author Driftay + * @author Vankka */ private static File file = new File(FactionsPlugin.getInstance().getDataFolder(), "discord_guilds.json"); diff --git a/src/main/java/com/massivecraft/factions/discord/DiscordSetupAttempt.java b/src/main/java/com/massivecraft/factions/discord/DiscordSetupAttempt.java index 7e990fde..9d0f5fec 100644 --- a/src/main/java/com/massivecraft/factions/discord/DiscordSetupAttempt.java +++ b/src/main/java/com/massivecraft/factions/discord/DiscordSetupAttempt.java @@ -1,5 +1,10 @@ package com.massivecraft.factions.discord; + +/** + * @author SaberTeam + */ + public class DiscordSetupAttempt { private Boolean success; private String reason; diff --git a/src/main/java/com/massivecraft/factions/discord/FactionChatHandler.java b/src/main/java/com/massivecraft/factions/discord/FactionChatHandler.java index 7dd0adeb..ee32afd0 100644 --- a/src/main/java/com/massivecraft/factions/discord/FactionChatHandler.java +++ b/src/main/java/com/massivecraft/factions/discord/FactionChatHandler.java @@ -22,6 +22,11 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; + +/** + * @author Vankka & SaberTeam + */ + public class FactionChatHandler extends ListenerAdapter { private FactionsPlugin plugin; diff --git a/src/main/java/com/massivecraft/factions/integration/Worldguard.java b/src/main/java/com/massivecraft/factions/integration/Worldguard.java index d4d625d3..17f942e9 100644 --- a/src/main/java/com/massivecraft/factions/integration/Worldguard.java +++ b/src/main/java/com/massivecraft/factions/integration/Worldguard.java @@ -8,6 +8,7 @@ import com.sk89q.worldguard.domains.Association; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.association.Associables; import com.sk89q.worldguard.protection.association.RegionAssociable; +import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; @@ -21,9 +22,7 @@ import org.bukkit.plugin.Plugin; import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import java.util.*; /* * WorldGuard Permission Checking. @@ -96,6 +95,42 @@ public class Worldguard { return associable; } + public static boolean isPvPDisabled(Location l) { + try { + ApplicableRegionSet regionSet = Objects.requireNonNull(instance.getRegionManager(l.getWorld())).getApplicableRegions(l); + if (regionSet.size() < 1) { + try { + return Objects.requireNonNull(Objects.requireNonNull(instance.getRegionManager(l.getWorld())).getRegion("__global__")).getFlags().get(DefaultFlag.PVP) == StateFlag.State.DENY; + } catch (Exception e) { + if (!(e instanceof NullPointerException)) { + e.printStackTrace(); + } + return false; + } + } else { + boolean return_flag = false; + int return_priority = -1; + for (ProtectedRegion region : regionSet) { + if (region.getFlags().containsKey(DefaultFlag.PVP)) { + StateFlag.State pvp_flag = (StateFlag.State) region.getFlags().get(DefaultFlag.PVP); + int region_priority = region.getPriority(); + if (return_priority == -1) { + return_flag = pvp_flag == StateFlag.State.DENY; + return_priority = region_priority; + } else if (region_priority > return_priority) { + return_flag = pvp_flag == StateFlag.State.DENY; + return_priority = region_priority; + } + } + } + + return return_flag; + } + } catch (Exception e) { + return false; + } + } + /** * Credits to the people listed above for using reflections to load WorldGuard 6.0 & 7.0 in 1 class! */ diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index ccf0d509..97d0a549 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -96,23 +96,26 @@ public class FactionsBlockListener implements Listener { boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId()))) return true; - else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { - me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); - if (shouldHurt) { - player.damage(Conf.actionDeniedPainAmount); - me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); - } - return false; - } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway - if (shouldHurt) { - player.damage(Conf.actionDeniedPainAmount); - if ((Board.getInstance().getFactionAt(loc).getTag(myFaction)) != null) - me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); - } - if (myFaction.getTag(me.getFaction()) != null && action != null) - me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); - return false; - } else if (access == Access.ALLOW) return true; + else { + String replace = TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()); + if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { + me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); + if (shouldHurt) { + player.damage(Conf.actionDeniedPainAmount); + me.msg(replace.replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); + } + return false; + } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway + if (shouldHurt) { + player.damage(Conf.actionDeniedPainAmount); + if ((Board.getInstance().getFactionAt(loc).getTag(myFaction)) != null) + me.msg(replace.replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); + } + if (myFaction.getTag(me.getFaction()) != null && action != null) + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); + return false; + } else if (access == Access.ALLOW) return true; + } me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); return false; } @@ -417,8 +420,9 @@ public class FactionsBlockListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onFrostWalker(EntityBlockFormEvent event) { - if (event.getEntity() == null || event.getEntity().getType() != EntityType.PLAYER || event.getBlock() == null) + if (event.getEntity() == null || event.getEntity().getType() != EntityType.PLAYER || event.getBlock() == null) { return; + } Player player = (Player) event.getEntity(); Location location = event.getBlock().getLocation(); @@ -426,10 +430,14 @@ public class FactionsBlockListener implements Listener { // only notify every 10 seconds FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); boolean justCheck = fPlayer.getLastFrostwalkerMessage() + 10000 > System.currentTimeMillis(); - if (!justCheck) fPlayer.setLastFrostwalkerMessage(); + if (!justCheck) { + fPlayer.setLastFrostwalkerMessage(); + } // Check if they have build permissions here. If not, block this from happening. - if (!playerCanBuildDestroyBlock(player, location, "frostwalk", justCheck)) event.setCancelled(true); + if (!playerCanBuildDestroyBlock(player, location, PermissableAction.FROST_WALK.toString(), justCheck)) { + event.setCancelled(true); + } } @EventHandler @@ -452,16 +460,6 @@ public class FactionsBlockListener implements Listener { e.setCancelled(true); } - @EventHandler - public void entityDamage(EntityDamageEvent e) { - if (!Conf.gracePeriod) return; - - if (e.getEntity() instanceof Player) { - if (e.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { - e.setCancelled(true); - } - } - } @EventHandler public void onTNTPlace(BlockPlaceEvent e1) { diff --git a/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java b/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java index 4e963d9e..2687d688 100644 --- a/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java +++ b/src/main/java/com/massivecraft/factions/shop/ShopGUIFrame.java @@ -21,6 +21,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; public class ShopGUIFrame { @@ -47,7 +48,7 @@ public class ShopGUIFrame { for (int a = 1; a <= items; a++) { String s = a + ""; int slot = ShopConfig.getShop().getInt("items." + s + ".slot"); - Material material = XMaterial.matchXMaterial(ShopConfig.getShop().getString("items." + s + ".block")).get().parseMaterial(); + Material material = XMaterial.matchXMaterial(Objects.requireNonNull(ShopConfig.getShop().getString("items." + s + ".block"))).get().parseMaterial(); int cost = ShopConfig.getShop().getInt("items." + s + ".cost"); String name = ShopConfig.getShop().getString("items." + s + ".name"); boolean glowing = ShopConfig.getShop().getBoolean("items." + s + ".glowing"); diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index 53843ec9..9cd66d13 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -814,8 +814,11 @@ public abstract class MemoryFPlayer implements FPlayer { setFlying(false); if (myFaction.isNormal() && !perm && myFaction.getFPlayers().isEmpty()) { // Remove this faction - for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) - fplayer.msg(TL.LEAVE_DISBANDED, myFaction.describeTo(fplayer, true)); + + if(FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast")) { + for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) + fplayer.msg(TL.LEAVE_DISBANDED, myFaction.describeTo(fplayer, true)); + } FactionDisbandEvent disbandEvent = new FactionDisbandEvent(getPlayer(), myFaction.getId(), PlayerDisbandReason.LEAVE); diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 32ee403e..50100410 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -674,6 +674,11 @@ public enum TL { COMMAND_PERM_TOP("RCT MEM OFF ALLY TRUCE NEUT ENEMY"), COMMAND_PERM_LOCKED("&cThis permission has been locked by the server"), + + COMMAND_POINTS_SHOW_DESCRIPTION("See the point balance of factions"), + COMMAND_POINTS_SHOW_WILDERNESS("&c&l[!] &7You may not check the point balance of wilderness!"), + COMMAND_POINTS_SHOW_OWN("&c&l[!] &7Your faction has &e%1$s &7points."), + COMMAND_POINTS_SHOW("&c&l[!] &e%1$s &7has a point balance of &b%2$s&7."), COMMAND_POINTS_FAILURE("&c&l[!] &c{faction} does not exist."), COMMAND_POINTS_SUCCESSFUL("&c&l[!] &7You have added &e%1$s &7points to &b%2$s&7. &b%2$s's &7New Point Balance: &e%3$s"), COMMAND_POINTS_INSUFFICIENT("&c&l[!] &7You may not add/set/remove a negative number of points to a faction!"),