From abbadb55ee82eab0623fd400ec848080f3ec21d7 Mon Sep 17 00:00:00 2001 From: ZeroEpoch1969 <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Wed, 29 Apr 2020 16:29:43 -0700 Subject: [PATCH] revert shop to names, next up mysql --- TotalFreedomMod.iml | 73 +---------------- pom.xml | 7 ++ .../totalfreedommod/ChatManager.java | 2 +- .../totalfreedommod/TotalFreedomMod.java | 7 +- .../totalfreedommod/banning/BanManager.java | 6 +- .../blocking/InteractBlocker.java | 7 ++ .../bridge/WorldGuardBridge.java | 2 + .../totalfreedommod/command/Command_ban.java | 1 + .../command/Command_consolesay.java | 4 +- .../command/Command_makeopregion.java | 1 + .../totalfreedommod/command/Command_say.java | 2 +- .../command/Command_setcompass.java | 2 +- .../totalfreedommod/command/Command_tag.java | 2 +- .../command/Command_vanish.java | 7 +- .../totalfreedommod/discord/Discord.java | 11 ++- .../totalfreedommod/fun/ItemFun.java | 12 +-- .../totalfreedommod/shop/Shop.java | 78 +++++++++++-------- .../totalfreedommod/shop/ShopData.java | 36 +++++---- .../totalfreedommod/world/WorldManager.java | 18 ++--- .../WorldRestrictions.java} | 63 +++++++++++---- 20 files changed, 169 insertions(+), 172 deletions(-) rename src/main/java/me/totalfreedom/totalfreedommod/{masterbuilder/MasterBuilderWorldRestrictions.java => world/WorldRestrictions.java} (62%) diff --git a/TotalFreedomMod.iml b/TotalFreedomMod.iml index 2cabfa76..c84a53a3 100644 --- a/TotalFreedomMod.iml +++ b/TotalFreedomMod.iml @@ -61,76 +61,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -228,5 +158,8 @@ + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 48a3b06f..ed03305a 100644 --- a/pom.xml +++ b/pom.xml @@ -225,6 +225,13 @@ provided + + net.goldtreeservers + worldguardextraflags + 4.0.0 + provided + + diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index 7b6c15eb..4d50d6ba 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -159,7 +159,7 @@ public class ChatManager extends FreedomService // Send to discord if (!ConfigEntry.ADMIN_ONLY_MODE.getBoolean() && !Bukkit.hasWhitelist()) { - plugin.dc.messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message)); + plugin.dc.messageChatChannel(plugin.dc.deformat(player.getName()) + " \u00BB " + ChatColor.stripColor(message)); } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 226c8338..e733bcdf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -39,7 +39,7 @@ import me.totalfreedom.totalfreedommod.fun.Trailer; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder; import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilderList; -import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilderWorldRestrictions; +import me.totalfreedom.totalfreedommod.world.WorldRestrictions; import me.totalfreedom.totalfreedommod.permissions.PermissionConfig; import me.totalfreedom.totalfreedommod.permissions.PermissionManager; import me.totalfreedom.totalfreedommod.player.PlayerList; @@ -127,7 +127,7 @@ public class TotalFreedomMod extends AeroPlugin public Trailer tr; public HTTPDaemon hd; public MasterBuilderList mbl; - public MasterBuilderWorldRestrictions mbwr; + public WorldRestrictions wr; public SignBlocker snp; public PlayerVerification pv; public EntityWiper ew; @@ -207,8 +207,7 @@ public class TotalFreedomMod extends AeroPlugin nu = services.registerService(AntiNuke.class); as = services.registerService(AntiSpam.class); mbl = services.registerService(MasterBuilderList.class); - mbwr = services.registerService(MasterBuilderWorldRestrictions.class); - //hwr = services.registerService(HubWorldRestrictions.class); + wr = services.registerService(WorldRestrictions.class); pl = services.registerService(PlayerList.class); sh = services.registerService(Shop.class); an = services.registerService(Announcer.class); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java index 35c9ac19..b7ed392d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java @@ -204,6 +204,7 @@ public class BanManager extends FreedomService saveAll(); return true; } + updateViews(); return false; } @@ -215,6 +216,7 @@ public class BanManager extends FreedomService saveAll(); return true; } + updateViews(); return false; } @@ -231,7 +233,7 @@ public class BanManager extends FreedomService return size; } - @EventHandler(priority = EventPriority.LOW) + @EventHandler(priority = EventPriority.NORMAL) public void onPlayerLogin(PlayerLoginEvent event) { final String username = event.getPlayer().getName(); @@ -250,7 +252,7 @@ public class BanManager extends FreedomService } } - @EventHandler(priority = EventPriority.LOW) + @EventHandler(priority = EventPriority.NORMAL) public void onPlayerJoin(PlayerJoinEvent event) { final Player player = event.getPlayer(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java index 5ce91afb..ac95a1eb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java @@ -161,6 +161,13 @@ public class InteractBlocker extends FreedomService event.setCancelled(true); break; } + case WRITTEN_BOOK: + { + player.getInventory().clear(player.getInventory().getHeldItemSlot()); + player.sendMessage(ChatColor.GRAY + "Books are currently disabled."); + event.setCancelled(true); + break; + } } } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java index afb7f4be..364c9983 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java @@ -22,6 +22,8 @@ public class WorldGuardBridge extends FreedomService @Override protected void onStart() { + plugin.wr.protectWorld(plugin.wm.hubworld.getWorld()); + plugin.wr.protectWorld(plugin.wm.masterBuilderWorld.getWorld()); } @Override diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java index ccda61f9..df2cf208 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java @@ -127,6 +127,7 @@ public class Command_ban extends FreedomCommand for (String ip : ips) { ban.addIp(ip); + ban.addIp(FUtil.getFuzzyIp(ip)); } plugin.bm.addBan(ban); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java index b92cede2..e49cc3d7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java @@ -24,8 +24,8 @@ public class Command_consolesay extends FreedomCommand } String message = StringUtils.join(args, " "); - FUtil.bcastMsg(String.format("§7[CONSOLE] §c%s §8» §f%s", sender.getName(), StringUtils.join(args, " "))); - plugin.dc.messageChatChannel("[CONSOLE] " + sender.getName() + " \u00BB " + ChatColor.stripColor(message)); + FUtil.bcastMsg(String.format("§7[CONSOLE] §c%s §8\u00BB §f%s", sender.getName(), StringUtils.join(args, " "))); + plugin.dc.messageChatChannel("[CONSOLE] " + plugin.dc.deformat(sender.getName()) + " \u00BB " + ChatColor.stripColor(message)); return true; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_makeopregion.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_makeopregion.java index 21aea054..e61f8642 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_makeopregion.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_makeopregion.java @@ -33,6 +33,7 @@ public class Command_makeopregion extends FreedomCommand put(Flags.DESTROY_VEHICLE, StateFlag.State.ALLOW); put(Flags.ENTITY_ITEM_FRAME_DESTROY, StateFlag.State.ALLOW); put(Flags.ENTITY_PAINTING_DESTROY, StateFlag.State.ALLOW); + put(net.goldtreeservers.worldguardextraflags.flags.Flags.WORLDEDIT, StateFlag.State.ALLOW); }}; public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java index 8b493629..c16f5082 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java @@ -41,7 +41,7 @@ public class Command_say extends FreedomCommand } FUtil.bcastMsg(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE); - plugin.dc.messageChatChannel(String.format("[Server:%s] \u00BB %s", sender.getName(), message)); + plugin.dc.messageChatChannel(String.format("[Server:%s] \u00BB %s", plugin.dc.deformat(sender.getName()), message)); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setcompass.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setcompass.java index bb995a37..898dc139 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setcompass.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setcompass.java @@ -7,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Set your compass to the specified position.", usage = "/ ") public class Command_setcompass extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java index d97434a7..219f2fe6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java @@ -180,7 +180,7 @@ public class Command_tag extends FreedomCommand plugin.pl.getPlayer(playerSender).setTag(outputTag); if (save) { - save(playerSender, outputTag); + save(playerSender, strippedTag); } msg("Tag set to '" + outputTag + ChatColor.GRAY + "'." + (save ? " (Saved)" : "")); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java index a3ae5e5a..f620a861 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java @@ -44,12 +44,7 @@ public class Command_vanish extends FreedomCommand } if (!silent) { - String beginning = sender.getName() + " is "; - if (admin.getLoginMessage().contains("%name%")) - { - beginning = ""; - } - FUtil.bcastMsg(ChatColor.AQUA + beginning + loginMsg); + FUtil.bcastMsg(plugin.rm.craftLoginMessage(playerSender, null)); FUtil.bcastMsg(playerSender.getName() + " joined the game.", ChatColor.YELLOW); plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**"); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 379ad368..837378a6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -331,13 +331,13 @@ public class Discord extends FreedomService @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { - messageChatChannel("**" + event.getPlayer().getName() + " joined the server" + "**"); + messageChatChannel("**" + deformat(event.getPlayer().getName()) + " joined the server" + "**"); } @EventHandler(priority = EventPriority.MONITOR) public void onPlayerLeave(PlayerQuitEvent event) { - messageChatChannel("**" + event.getPlayer().getName() + " left the server" + "**"); + messageChatChannel("**" + deformat(event.getPlayer().getName()) + " left the server" + "**"); } @EventHandler(priority = EventPriority.MONITOR) @@ -354,7 +354,7 @@ public class Discord extends FreedomService { } - messageChatChannel("**" + event.getDeathMessage() + "**"); + messageChatChannel("**" + deformat(event.getDeathMessage()) + "**"); } @Override @@ -430,6 +430,11 @@ public class Discord extends FreedomService FLog.info("Discord verification bot has successfully shutdown."); } + public String deformat(String input) + { + return input.replace("_", "\\_"); + } + public boolean sendReport(Player reporter, Player reported, String reason) { if (ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString().isEmpty()) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index c6d3484d..0f484b2c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -189,17 +189,7 @@ public class ItemFun extends FreedomService case CARROT: { - if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) - { - break; - } - - if (!plugin.al.isSeniorAdmin(player)) - { - break; - } - - if (player.getWorld().equals(plugin.wm.masterBuilderWorld.getWorld()) && plugin.mbwr.doRestrict(player)) + if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean() || !plugin.al.isSeniorAdmin(player) || plugin.wr.doRestrict(player)) { break; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java index fd125665..4295c063 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java @@ -16,6 +16,7 @@ import me.rayzr522.jsonmessage.JSONMessage; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.playerverification.VPlayer; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import net.pravian.aero.config.YamlConfig; @@ -37,7 +38,7 @@ import org.bukkit.scheduler.BukkitTask; public class Shop extends FreedomService { @Getter - public final Map dataMap = Maps.newHashMap(); + public final Map dataMap = Maps.newHashMap(); @Getter private final File configFolder; private BukkitTask reactions; @@ -102,8 +103,8 @@ public class Shop extends FreedomService YamlConfig config = getConfig(data); data.saveTo(config); config.save(); - dataMap.remove(data.getUUID()); - dataMap.put(data.getUUID(), data); + dataMap.remove(data.getUsername()); + dataMap.put(data.getUsername(), data); } public String getShopPrefix() @@ -119,30 +120,29 @@ public class Shop extends FreedomService // May not return null public ShopData getData(Player player) { - // Check already loaded - ShopData data = dataMap.get(player.getUniqueId()); + // Check for existing data + ShopData data = dataMap.get(player.getName()); if (data != null) { return data; } // Load data - data = getData(player.getUniqueId()); + data = getData(player.getName()); - // Create data if nonexistent + String ip = Ips.getIp(player); + + // Create new data if nonexistent if (data == null) { - FLog.info("Creating new shop data entry for " + player.getName()); + FLog.info("Creating new player verification entry for " + player.getName()); // Create new player data = new ShopData(player); - data.setUsername(player.getName()); - - // Set defaults - data.setCoins(0); + data.addIp(Ips.getIp(player)); // Store player - dataMap.put(player.getUniqueId(), data); + dataMap.put(player.getName(), data); // Save player YamlConfig config = getConfig(data); @@ -150,34 +150,46 @@ public class Shop extends FreedomService config.save(); } - dataMap.put(player.getUniqueId(), data); + if (!data.getsIps().contains(ip)) + { + data.addIp(ip); + save(data); + } return data; } public ShopData getData(String username) { - UUID uuid = FUtil.nameToUUID(username); - if (uuid != null) - { - return getData(uuid); - } - return null; - } + username = username.toLowerCase(); - public ShopData getData(UUID uuid) - { - // Check if the player is a known player - final File configFile = getConfigFile(uuid); + final File configFile = getConfigFile(username); if (!configFile.exists()) { return null; } - // Load entry - final ShopData data = new ShopData(uuid); - data.loadFrom(getConfig(data)); - return data; + final ShopData shopData = new ShopData(username); + shopData.loadFrom(getConfig(shopData)); + + if (!shopData.isValid()) + { + FLog.warning("Could not load player verification entry for " + username + ". Entry is not valid!"); + configFile.delete(); + return null; + } + + // Only store data in map if the player is online + for (Player players : server.getOnlinePlayers()) + { + if (players.getName().equals(username)) + { + dataMap.put(username, shopData); + return shopData; + } + } + + return shopData; } public Inventory generateShopGUI(ShopData shopData) @@ -329,7 +341,7 @@ public class Shop extends FreedomService } Player player = (Player) event.getWhoClicked(); - ShopData shopData = plugin.sh.getData(player); + ShopData shopData = getData(player); int price = shopItem.getCost(); int coins = shopData.getCoins(); @@ -420,14 +432,14 @@ public class Shop extends FreedomService return dataMap.values(); } - protected File getConfigFile(UUID uuid) + protected File getConfigFile(String name) { - return new File(getConfigFolder(), uuid + ".yml"); + return new File(getConfigFolder(), name.toLowerCase() + ".yml"); } protected YamlConfig getConfig(ShopData data) { - final YamlConfig config = new YamlConfig(plugin, getConfigFile(data.getUUID()), false); + final YamlConfig config = new YamlConfig(plugin, getConfigFile(data.getUsername()), false); config.load(); return config; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java index 3460fb78..b4a9bde0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java @@ -16,6 +16,7 @@ import org.bukkit.entity.Player; public class ShopData implements ConfigLoadable, ConfigSavable, Validatable { + private final List ips = Lists.newArrayList(); @Getter @Setter private String username; @@ -30,19 +31,19 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable public ShopData(Player player) { - this(player.getUniqueId()); + this(player.getName()); } - public ShopData(UUID uuid) + public ShopData(String name) { - this.uuid = uuid.toString(); + this.username = name; } @Override public void loadFrom(ConfigurationSection cs) { this.username = cs.getString("username", username); - this.uuid = cs.getString("uuid", uuid); + this.ips.addAll(cs.getStringList("ips")); this.coins = cs.getInt("coins", coins); this.items.addAll(cs.getStringList("items")); this.totalVotes = cs.getInt("totalVotes"); @@ -53,7 +54,7 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable { Validate.isTrue(isValid(), "Could not save shop entry: " + username + ". Entry not valid!"); cs.set("username", username); - cs.set("uuid", uuid); + cs.set("ips", ips); cs.set("coins", coins); cs.set("items", items); cs.set("totalVotes", totalVotes); @@ -64,16 +65,6 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable return Collections.unmodifiableList(items); } - public void setUUID(UUID id) - { - uuid = id.toString(); - } - - public UUID getUUID() - { - return UUID.fromString(uuid); - } - public void giveItem(ShopItem item) { items.add(item.getDataName()); @@ -88,6 +79,21 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable return false; } + public boolean addIp(String ip) + { + return !ips.contains(ip) && ips.add(ip); + } + + public void removeIp(String ip) + { + ips.remove(ip); + } + + public List getsIps() + { + return Collections.unmodifiableList(ips); + } + public void removeItem(ShopItem item) { items.remove(item.getDataName()); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java index 371a4d03..45548150 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java @@ -9,7 +9,6 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -25,7 +24,7 @@ public class WorldManager extends FreedomService public Flatlands flatlands; public AdminWorld adminworld; public MasterBuilderWorld masterBuilderWorld; - //public HubWorld hubworld; + public HubWorld hubworld; public WorldManager(TotalFreedomMod plugin) { @@ -34,7 +33,7 @@ public class WorldManager extends FreedomService this.flatlands = new Flatlands(); this.adminworld = new AdminWorld(); this.masterBuilderWorld = new MasterBuilderWorld(); - //this.hubworld = new HubWorld(); + this.hubworld = new HubWorld(); } @Override @@ -43,7 +42,8 @@ public class WorldManager extends FreedomService flatlands.getWorld(); adminworld.getWorld(); masterBuilderWorld.getWorld(); - //hubworld.getWorld(); + hubworld.getWorld(); + // Disable weather if (ConfigEntry.DISABLE_WEATHER.getBoolean()) { @@ -63,7 +63,7 @@ public class WorldManager extends FreedomService flatlands.getWorld().save(); adminworld.getWorld().save(); masterBuilderWorld.getWorld().save(); - //hubworld.getWorld().save(); + hubworld.getWorld().save(); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -113,10 +113,10 @@ public class WorldManager extends FreedomService { return; } - /*else if (event.getWorld().equals(hubworld.getWorld()) && hubworld.getWeatherMode() != WorldWeather.OFF) + else if (event.getWorld().equals(hubworld.getWorld()) && hubworld.getWeatherMode() != WorldWeather.OFF) { return; - }*/ + } } catch (Exception ex) { @@ -141,10 +141,10 @@ public class WorldManager extends FreedomService { return; } - /*else if (event.getWorld().equals(hubworld.getWorld()) && hubworld.getWeatherMode() != WorldWeather.OFF) + else if (event.getWorld().equals(hubworld.getWorld()) && hubworld.getWeatherMode() != WorldWeather.OFF) { return; - }*/ + } } catch (Exception ex) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/masterbuilder/MasterBuilderWorldRestrictions.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java similarity index 62% rename from src/main/java/me/totalfreedom/totalfreedommod/masterbuilder/MasterBuilderWorldRestrictions.java rename to src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java index 4b94d14d..feeb9bc4 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/masterbuilder/MasterBuilderWorldRestrictions.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java @@ -1,11 +1,19 @@ -package me.totalfreedom.totalfreedommod.masterbuilder; +package me.totalfreedom.totalfreedommod.world; +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -16,13 +24,25 @@ import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; -public class MasterBuilderWorldRestrictions extends FreedomService +public class WorldRestrictions extends FreedomService { - public final List BLOCKED_WORLDEDIT_COMMANDS = Arrays.asList( + private final List BLOCKED_WORLDEDIT_COMMANDS = Arrays.asList( "green", "fixlava", "fixwater", "br", "brush", "tool", "mat", "range", "cs", "up", "fill", "setblock", "tree", "replacenear"); - public MasterBuilderWorldRestrictions(TotalFreedomMod plugin) + private final Map, Object> flags = new HashMap, Object>() + {{ + put(Flags.BLOCK_PLACE, StateFlag.State.DENY); + put(Flags.BLOCK_BREAK, StateFlag.State.DENY); + put(Flags.BUILD, StateFlag.State.DENY); + put(Flags.PLACE_VEHICLE, StateFlag.State.DENY); + put(Flags.DESTROY_VEHICLE, StateFlag.State.DENY); + put(Flags.ENTITY_ITEM_FRAME_DESTROY, StateFlag.State.DENY); + put(Flags.ENTITY_PAINTING_DESTROY, StateFlag.State.DENY); + put(net.goldtreeservers.worldguardextraflags.flags.Flags.WORLDEDIT, StateFlag.State.DENY); + }}; + + public WorldRestrictions(TotalFreedomMod plugin) { super(plugin); } @@ -39,9 +59,12 @@ public class MasterBuilderWorldRestrictions extends FreedomService public boolean doRestrict(Player player) { - if (!plugin.mbl.isMasterBuilder(player) && !FUtil.canManageMasterBuilders(player.getName()) && player.getWorld().equals(plugin.wm.masterBuilderWorld.getWorld())) + if (!plugin.mbl.isMasterBuilder(player) && !FUtil.canManageMasterBuilders(player.getName())) { - return true; + if (player.getWorld().equals(plugin.wm.masterBuilderWorld.getWorld()) || player.getWorld().equals(plugin.wm.hubworld.getWorld())) + { + return true; + } } return false; @@ -117,18 +140,32 @@ public class MasterBuilderWorldRestrictions extends FreedomService if (command.startsWith("/") || BLOCKED_WORLDEDIT_COMMANDS.contains(command)) { - player.sendMessage(ChatColor.RED + "Only Master Builders are allowed to use WorldEdit in the Master Builder world."); + player.sendMessage(ChatColor.RED + "Only Master Builders are allowed to use WorldEdit here."); event.setCancelled(true); } - if (!plugin.al.isSeniorAdmin(player)) + if (command.equals("coreprotect") || command.equals("core") || command.equals("co")) { - if (command.equals("coreprotect") || command.equals("co")) - { - player.sendMessage(ChatColor.RED + "Only Senior Admins are allowed to use CoreProtect in the Master Builder world."); - event.setCancelled(true); - } + player.sendMessage(ChatColor.RED + "Only Master Builders are allowed to use CoreProtect here."); + event.setCancelled(true); } } } + + + public void protectWorld(World world) + { + if (!plugin.wgb.isEnabled()) + { + return; + } + + RegionManager regionManager = plugin.wgb.getRegionManager(world); + + ProtectedRegion region = regionManager.getRegion("__global__"); + + region.setFlags(flags); + + regionManager.addRegion(region); + } }