diff --git a/.travis.yml b/.travis.yml index 4547e44b..5a160925 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ before_deploy: language: java deploy: provider: releases - user: ProSavage + user: Driftay password: secure: l/4sN0iN3JeG5wf/8ijJMmsF3aG4CW8aaIK1+BWBhzJJFLTOfvIejID8Q/AV9rHQlp/QUOYXbCO8+y/VFFJ3pN8FLd1plqawXhGAjIVIBVKfpbdEcIlNHSsrIhUszGo5C+AqhR3YOmRN5C3whJXqRbjSIxlI4wb9Bzg4Rwe1lguhw2/q0b7r/4OQ1klZIeM6oPP/2WWjhIerpeayInLs5zm+oMyj0idrdoZLHK171u+/ou/r7DxkU37sAyC8lWUxntftCzNq4/OxzpL4VsxM6OW69OCY8SOqiUDp+IxXbxWNgHcDi0UsRr/skmb0vI+FFUlaXg6pVQpQYHQLgpiYIr32Z7F3HYeXo9hgid9zRNAVN2nSXBASuaJUsuXFCPa+HASaHi+7Rj6icVyYN6fhf1+kyw11htwmNjlOKUYPpN7/wRdPjFYcqFmcO7X12jyyQfGJf1TxkatH2EcoYO6QYP25lbGyDUluPw9GF37j/cGrYlGIslJXtLU0vwSdg8ytt0xw2llm23CitjfFE8XJ4PkUHTRa/W4ba/NVkhD/SEzS/ZdyQH37v4AVU361yUNxnZ9gCCzxH5Gj6K0sZ+pA0cVHkjvYebN4qBPfo0RAP0MHZLVqFQX4t/7oUP/+V6aaH7w/4j0MNBNhGLl2jFs3o8ZKtUptw3NskgimsYf7ThM= file: target/Factions.jar diff --git a/src/main/java/com/massivecraft/factions/Conf.java b/src/main/java/com/massivecraft/factions/Conf.java index 8def02dd..8abd1117 100644 --- a/src/main/java/com/massivecraft/factions/Conf.java +++ b/src/main/java/com/massivecraft/factions/Conf.java @@ -341,7 +341,11 @@ public class Conf { // Default Options - Is this even shown on the Conf.json? public static transient HashMap defaultFactionPermissions = new HashMap<>(); - // Custom Ranks - Oof I forgot I was doing this _SvenjaReissaus_ + + //Cooldown for /f logout in seconds + public static long logoutCooldown = 30; + + // Custom Ranks - Oof I forgot I was doing this _SvenjaReissaus_ //public static boolean enableCustomRanks = false; // We will disable it by default to avoid any migration error //public static int maxCustomRanks = 2; // Setting this to -1 will allow unlimited custom ranks // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/factions/SaberFactions.java b/src/main/java/com/massivecraft/factions/SaberFactions.java index 6790bd9b..6a6a9ba9 100644 --- a/src/main/java/com/massivecraft/factions/SaberFactions.java +++ b/src/main/java/com/massivecraft/factions/SaberFactions.java @@ -259,7 +259,7 @@ public class SaberFactions extends MPlugin { divider(); System.out.println("You are using a BETA version of the plugin!"); System.out.println("This comes with risks of small bugs in newer features!"); - System.out.println("For support head to: https://github.com/ProSavage/SaberFactions/issues"); + System.out.println("For support head to: https://github.com/Driftay/Saber-Factions/issues"); divider(); } @@ -274,8 +274,6 @@ public class SaberFactions extends MPlugin { return skriptAddon; } - - private void setupPlaceholderAPI() { Plugin clip = getServer().getPluginManager().getPlugin("PlaceholderAPI"); if (clip != null && clip.isEnabled()) { diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 062332c1..439dc906 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -5,6 +5,7 @@ import com.massivecraft.factions.SaberFactions; import com.massivecraft.factions.cmd.alts.CmdAlts; import com.massivecraft.factions.cmd.claim.*; import com.massivecraft.factions.cmd.econ.CmdMoney; +import com.massivecraft.factions.cmd.logout.CmdLogout; import com.massivecraft.factions.cmd.points.CmdPoints; import com.massivecraft.factions.cmd.relational.CmdRelationAlly; import com.massivecraft.factions.cmd.relational.CmdRelationEnemy; @@ -124,6 +125,7 @@ public class FCmdRoot extends FCommand { public CmdFGlobal cmdFGlobal = new CmdFGlobal(); public CmdViewChest cmdViewChest = new CmdViewChest(); public CmdPoints cmdPoints = new CmdPoints(); + public CmdLogout cmdLogout = new CmdLogout(); @@ -193,6 +195,7 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdStatus); this.addSubCommand(this.cmdStealth); this.addSubCommand(this.cmdStuck); + this.addSubCommand(this.cmdLogout); this.addSubCommand(this.cmdTag); this.addSubCommand(this.cmdTitle); this.addSubCommand(this.cmdUnclaim); diff --git a/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java b/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java new file mode 100644 index 00000000..2d7267e2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.cmd.logout; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.cmd.FCommand; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdLogout extends FCommand { + + public CmdLogout(){ + super(); + this.aliases.add("logout"); + + this.permission = Permission.LOGOUT.node; + this.disableOnLock = true; + this.disableOnSpam = true; + + senderMustBePlayer = true; + senderMustBeMember = false; + senderMustBeModerator = false; + senderMustBeAdmin = false; + } + + @Override + public void perform() { + LogoutHandler handler = LogoutHandler.getByName(fme.getPlayer().getName()); + + if(handler.isLogoutActive(fme.getPlayer())){ + fme.msg(TL.COMMAND_LOGOUT_ACTIVE); + return; + } + + handler.applyLogoutCooldown(fme.getPlayer()); + fme.msg(TL.COMMAND_LOGOUT_LOGGING, Conf.logoutCooldown); + } + + @Override + public TL getUsageTranslation() { return TL.COMMAND_LOGOUT_DESCRIPTION; } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java b/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java new file mode 100644 index 00000000..ee9a9eb8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.cmd.logout; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.SaberFactions; +import com.massivecraft.factions.zcore.util.TL; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class LogoutHandler { + + public static Map factionDatas = new HashMap<>(); + private Map logoutCooldown = new HashMap<>(); + private String name; + + public LogoutHandler(String name) { + this.name = name; + factionDatas.put(name, this); + } + + public boolean isLogoutActive(Player player) { + return logoutCooldown.containsKey(player.getUniqueId()) && System.currentTimeMillis() < logoutCooldown.get(player.getUniqueId()); + } + + public void cancelLogout(Player player) { + if(logoutCooldown.containsKey(player.getUniqueId())) { + logoutCooldown.remove(player.getUniqueId()); + } + } + + public void applyLogoutCooldown(Player player) { + logoutCooldown.put(player.getUniqueId(), System.currentTimeMillis() + (30 * 1000)); + + Bukkit.getScheduler().runTaskLater(SaberFactions.plugin, () -> { + if(isLogoutActive(player)) { + player.setMetadata("Logout", new FixedMetadataValue(SaberFactions.plugin, true)); + player.kickPlayer(String.valueOf(TL.COMMAND_LOGOUT_KICK_MESSAGE)); + cancelLogout(player); + } + }, Conf.logoutCooldown * 20L); + } + + public static LogoutHandler getByName(String name) { + LogoutHandler logoutHandler = factionDatas.get(name); + return logoutHandler == null ? new LogoutHandler(name) : factionDatas.get(name); + } +} diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index ae089061..dcf6061a 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.cmd.CmdFGlobal; import com.massivecraft.factions.cmd.CmdFly; import com.massivecraft.factions.cmd.CmdSeeChunk; +import com.massivecraft.factions.cmd.logout.LogoutHandler; import com.massivecraft.factions.event.FPlayerEnteredFactionEvent; import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent; @@ -410,7 +411,7 @@ public class FactionsPlayerListener implements Listener { } public void enableFly(FPlayer me) { - if(!me.getPlayer().hasPermission("factions.fly")) return; + if (!me.getPlayer().hasPermission("factions.fly")) return; if (SaberFactions.plugin.getConfig().getBoolean("ffly.AutoEnable")) { me.setFlying(true); @@ -736,6 +737,39 @@ public class FactionsPlayerListener implements Listener { } } + @EventHandler + public void onLogoutMove(PlayerMoveEvent e) { + LogoutHandler handler = LogoutHandler.getByName(e.getPlayer().getName()); + if (handler.isLogoutActive(e.getPlayer())) { + handler.cancelLogout(e.getPlayer()); + e.getPlayer().sendMessage(String.valueOf(TL.COMMAND_LOGOUT_MOVED)); + } + } + + @EventHandler + public void onDamage(EntityDamageEvent e) { + if (e.getEntity() instanceof Player) { + Player player = (Player) e.getEntity(); + LogoutHandler handler = LogoutHandler.getByName(player.getName()); + if (handler.isLogoutActive(player)) { + handler.cancelLogout(player); + player.sendMessage(String.valueOf(TL.COMMAND_LOGOUT_DAMAGE_TAKEN)); + } + } + } + + @EventHandler + public void onTeleport(PlayerTeleportEvent e) { + Player player = e.getPlayer(); + + if (player == null) return; + LogoutHandler handler = LogoutHandler.getByName(player.getName()); + if (handler.isLogoutActive(player)) { + handler.cancelLogout(player); + player.sendMessage(String.valueOf(TL.COMMAND_LOGOUT_TELEPORTED)); + } + } + @EventHandler(priority = EventPriority.HIGH) public void onPlayerInteractGUI(InventoryClickEvent event) { if (event.getClickedInventory() == null) { @@ -971,23 +1005,23 @@ public class FactionsPlayerListener implements Listener { } @EventHandler - public void AsyncPlayerChatEvent(AsyncPlayerChatEvent e){ + public void AsyncPlayerChatEvent(AsyncPlayerChatEvent e) { Player p = e.getPlayer(); - if (CmdFGlobal.toggled.contains(p.getUniqueId())){ + if (CmdFGlobal.toggled.contains(p.getUniqueId())) { //they're muted, check status of Faction Chat - if (FPlayers.getInstance().getByPlayer(p).getFaction() == null) { - //they're muted, and not in a faction, cancel and return + if (FPlayers.getInstance().getByPlayer(p).getFaction() == null) { + //they're muted, and not in a faction, cancel and return + e.setCancelled(true); + return; + } else { + //are in a faction that's not Wilderness, SafeZone, or Warzone, check their chat status + if (!FPlayers.getInstance().getByPlayer(p).getChatMode().isAtLeast(ChatMode.ALLIANCE)) { + //their Faction Chat Mode is not at-least a Alliance, cancel and return e.setCancelled(true); return; - } else { - //are in a faction that's not Wilderness, SafeZone, or Warzone, check their chat status - if (!FPlayers.getInstance().getByPlayer(p).getChatMode().isAtLeast(ChatMode.ALLIANCE)) { - //their Faction Chat Mode is not at-least a Alliance, cancel and return - e.setCancelled(true); - return; - } } + } } //we made it this far, since we didn't return yet, we must have sent the chat event through @@ -995,10 +1029,10 @@ public class FactionsPlayerListener implements Listener { List l = new ArrayList<>(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); - if (recipient != null){ - if (CmdFGlobal.toggled.contains(recipient.getUniqueId())){ + if (recipient != null) { + if (CmdFGlobal.toggled.contains(recipient.getUniqueId())) { e.getRecipients().remove(recipient); } } diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index f0b7e46e..05b563bb 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -46,6 +46,7 @@ public enum Permission { LEAVE("leave"), LIST("list"), LOCK("lock"), + LOGOUT("logout"), MAP("map"), MAPHEIGHT("mapheight"), MOD("mod"), diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/DefaultPermissions.java b/src/main/java/com/massivecraft/factions/zcore/fperms/DefaultPermissions.java index 74748b4e..52a43874 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/DefaultPermissions.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/DefaultPermissions.java @@ -63,32 +63,32 @@ public class DefaultPermissions { } public DefaultPermissions(boolean canBan, - boolean canBuild, - boolean canDestory, - boolean canFrostwalk, - boolean canPainbuild, - boolean canDoor, - boolean canButton, - boolean canLever, - boolean canContainer, - boolean canInvite, - boolean canKick, - boolean canItems, - boolean canSethome, - boolean canTerritory, - boolean canAccess, - boolean canHome, - boolean canDisband, - boolean canPromote, - boolean canSetwarp, - boolean canWarp, - boolean canFly, - boolean canVault, - boolean canTntbank, - boolean canTntfill, - boolean canWithdraw, - boolean canChest, - boolean canSpawners) { + boolean canBuild, + boolean canDestory, + boolean canFrostwalk, + boolean canPainbuild, + boolean canDoor, + boolean canButton, + boolean canLever, + boolean canContainer, + boolean canInvite, + boolean canKick, + boolean canItems, + boolean canSethome, + boolean canTerritory, + boolean canAccess, + boolean canHome, + boolean canDisband, + boolean canPromote, + boolean canSetwarp, + boolean canWarp, + boolean canFly, + boolean canVault, + boolean canTntbank, + boolean canTntfill, + boolean canWithdraw, + boolean canChest, + boolean canSpawners) { this.ban = canBan; this.build = canBuild; this.destroy = canDestory; @@ -128,6 +128,7 @@ public class DefaultPermissions { else if (name == "door") return this.door; else if (name == "button") return this.button; else if (name == "lever") return this.lever; + else if (name == "home") return this.home; else if (name == "container") return this.container; else if (name == "invite") return this.invite; else if (name == "kick") return this.kick; @@ -135,7 +136,6 @@ public class DefaultPermissions { else if (name == "sethome") return this.sethome; else if (name == "territory") return this.territory; else if (name == "access") return this.access; - else if (name == "home") return this.home; else if (name == "disband") return this.disband; else if (name == "promote") return this.promote; else if (name == "setwarp") return this.setwarp; diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java index 6dfea42b..318545d6 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java @@ -109,7 +109,6 @@ public enum PermissableAction { Access access = fme.getFaction().getAccess(permissable, this); if (access == null) access = Access.UNDEFINED; - ItemStack item = new ItemStack(material); ItemMeta itemMeta = item.getItemMeta(); @@ -130,7 +129,6 @@ public enum PermissableAction { // If under the 1.13 version we will use the colorable option. if (!SaberFactions.plugin.mc113 && !SaberFactions.plugin.mc114) { //TODO see if it's working in other version than 1.13 and 1.14 - DyeColor dyeColor = null; try { @@ -144,10 +142,10 @@ public enum PermissableAction { } } else { Material mat = XMaterial.CYAN_GLAZED_TERRACOTTA.parseMaterial(); - switch (accessValue) { - case "deny": mat = XMaterial.RED_GLAZED_TERRACOTTA.parseMaterial(); break; - case "allow": mat = XMaterial.GREEN_GLAZED_TERRACOTTA.parseMaterial(); break; - case "undefined": mat = XMaterial.CYAN_GLAZED_TERRACOTTA.parseMaterial(); break; + switch (accessValue) { + case "deny": mat = XMaterial.RED_GLAZED_TERRACOTTA.parseMaterial(); break; + case "allow": mat = XMaterial.GREEN_GLAZED_TERRACOTTA.parseMaterial(); break; + case "undefined": mat = XMaterial.CYAN_GLAZED_TERRACOTTA.parseMaterial(); break; } item.setType(mat); } 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 537ebd2e..aed43f19 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -761,7 +761,7 @@ public abstract class MemoryFPlayer implements FPlayer { fplayer.msg(TL.LEAVE_DISBANDED, myFaction.describeTo(fplayer, true)); } - FactionDisbandEvent disbandEvent = new FactionDisbandEvent(null, getId(), PlayerDisbandReason.LEAVE); + FactionDisbandEvent disbandEvent = new FactionDisbandEvent(getPlayer(), myFaction.getId(), PlayerDisbandReason.LEAVE); Bukkit.getPluginManager().callEvent(disbandEvent); Factions.getInstance().removeFaction(myFaction.getId()); diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index 24829691..b9c34c89 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -731,9 +731,9 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { // Put the map in there for each relation. for (Relation relation : Relation.values()) { if (relation != Relation.MEMBER) { - if (!Conf.defaultFactionPermissions.containsKey(relation.nicename.toUpperCase())) + if (!Conf.defaultFactionPermissions.containsKey(relation.nicename.toUpperCase())) { permissions.put(relation, new HashMap<>(defaultMap)); - else + } else permissions.put(relation, PermissableAction.fromDefaults(Conf.defaultFactionPermissions.get(relation.nicename.toUpperCase()))); } } @@ -743,11 +743,11 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { if (role != Role.LEADER) { if (!Conf.defaultFactionPermissions.containsKey(role.nicename.toUpperCase())) permissions.put(role, new HashMap<>(defaultMap)); - else + } else { permissions.put(role, PermissableAction.fromDefaults(Conf.defaultFactionPermissions.get(role.nicename.toUpperCase()))); + } } } - } /** * Read only map of Permissions. 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 13d3beae..69567acb 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -692,6 +692,14 @@ public enum TL { COMMAND_GETVAULT_NOMONEY("&cYou do not have enough money"), COMMAND_GETVAULT_MONEYTAKE("&c{amount} has been taken from your account"), + COMMAND_LOGOUT_KICK_MESSAGE("&2You have safely logged out!"), + COMMAND_LOGOUT_ACTIVE("&c&l[!] &7You are already logging out!"), + COMMAND_LOGOUT_LOGGING("&c&l[!] &7You are logging out. Please wait &b%1$s &7seconds."), + COMMAND_LOGOUT_DESCRIPTION("logout safely from the server"), + COMMAND_LOGOUT_MOVED("&c&l[!] &7Your logout was cancelled because you moved!"), + COMMAND_LOGOUT_DAMAGE_TAKEN("&c&l[!] &7Your logout was cancelled because you were damaged!"), + COMMAND_LOGOUT_TELEPORTED("&c&l[!] &7Your logout was cancelled because you teleported!"), + COMMAND_SHOW_NOFACTION_SELF("You are not in a faction"), COMMAND_SHOW_NOFACTION_OTHER("That's not a faction"), COMMAND_SHOW_TOSHOW("to show faction information"), @@ -772,19 +780,6 @@ public enum TL { COMMAND_TOGGLESB_DISABLED("You can't toggle scoreboards while they are disabled."), - SHOP_POTION_TITLE("&c&lPotion Shop"), - SHOP_POTION_GUI_ACTIVATED_LORE_LINE("&a&lPotion Type Active"), - SHOP_POTION_GUI_ACTIVATED("&d%1$s activated &f%2$s &dfor your faction!"), - SHOP_POTION_GUI_INSUFFICIENT_POINTS("&c&l[!] &7Your faction can't afford that, you need &d%1$s &7faction points"), - SHOP_POTION_GUI_POTION_TYPE_ALREADY_ACTIVE("&c&l[!] &7This Potion Type is Already Active for Your Faction!"), - SHOP_POTION_GUI_MAX_REACHED("&c&l[!] &7You may not have more than %1$s potions at the same time"), - - SHOP_BOOSTER_TITLE("&b&lBooster Shop"), - SHOP_GUI_BOOSTER_MAX_REACHED("&c&l[!] &7You may not have more than %1$s boosters at the same time"), - SHOP_GUI_BOOSTER_ACTIVE_ALREADY_ACTIVE("&a&lActive"), - SHOP_GUI_BOOSTER_CANNOT_AFFORD("&c&l[!] &7Your faction can't afford that, you need &d%1$s faction points"), - SHOP_GUI_BOOSTER_ACTIVE_LORE_LINE("&a&lActive"), - COMMAND_TOP_DESCRIPTION("Sort Factions to see the top of some criteria."), COMMAND_TOP_TOP("Top Factions by %s. Page %d/%d"), diff --git a/src/main/resources/lang/it_IT.yml b/src/main/resources/lang/it_IT.yml index 4af7d7ab..775fc25c 100644 --- a/src/main/resources/lang/it_IT.yml +++ b/src/main/resources/lang/it_IT.yml @@ -1,4 +1,4 @@ -# Lang file for SaberFactions by drtshock & ProSavage +# Lang file for SaberFactions by drtshock & Driftay # Use & for color codes. # Made with love <3