From a51f5c9bbfae2665b229e6ffff267ddbe9a956d4 Mon Sep 17 00:00:00 2001 From: Video Date: Fri, 3 Sep 2021 13:53:33 -0600 Subject: [PATCH 1/3] FS-273 --- .../command/Command_trail.java | 12 ++++++++-- .../totalfreedommod/config/ConfigEntry.java | 1 + .../totalfreedommod/fun/Trailer.java | 24 +++++++++++-------- .../totalfreedommod/shop/ShopItem.java | 20 ++++++++++++---- src/main/resources/config.yml | 1 + 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java index 44129bd4..16d82e97 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java @@ -1,11 +1,13 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.shop.ShopItem; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Trails rainbow wool behind you as you walk/fly.", usage = "/") public class Command_trail extends FreedomCommand { @@ -13,6 +15,12 @@ public class Command_trail extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + if (!plugin.pl.getData(playerSender).hasItem(ShopItem.RAINBOW_TRAIL)) + { + msg("You didn't purchase the ability to have a " + ShopItem.RAINBOW_TRAIL.getName() + "! Purchase it from the shop.", ChatColor.RED); + return true; + } + if (plugin.tr.contains(playerSender)) { plugin.tr.remove(playerSender); @@ -21,7 +29,7 @@ public class Command_trail extends FreedomCommand else { plugin.tr.add(playerSender); - msg("Trail enabled. Use \"/trail off\" to disable."); + msg("Trail enabled. Run this command again to disable it."); } return true; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 021f30f1..4f127737 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -110,6 +110,7 @@ public enum ConfigEntry SHOP_PRICES_STACKING_POTATO(Integer.class, "shop.prices.stacking_potato"), SHOP_PRICES_CLOWN_FISH(Integer.class, "shop.prices.clown_fish"), SHOP_PRICES_LOGIN_MESSAGES(Integer.class, "shop.prices.login_messages"), + SHOP_PRICES_RAINBOW_TRAIL(Integer.class, "shop.prices.rainbow_trail"), // ADMINLIST_CLEAN_THESHOLD_HOURS(Integer.class, "adminlist.clean_threshold_hours"), ADMINLIST_CONSOLE_IS_ADMIN(Boolean.class, "adminlist.console_is_admin"), diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java index 012dc4d7..382589e8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java @@ -1,10 +1,9 @@ package me.totalfreedom.totalfreedommod.fun; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; -import java.util.SplittableRandom; +import java.util.*; + import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.shop.ShopItem; import me.totalfreedom.totalfreedommod.util.Groups; import org.bukkit.Location; import org.bukkit.Material; @@ -18,7 +17,7 @@ import org.bukkit.event.player.PlayerMoveEvent; public class Trailer extends FreedomService { private final SplittableRandom random = new SplittableRandom(); - private final Set trailPlayers = new HashSet<>(); // player name + private final Set trailPlayers = new HashSet<>(); // player name @Override public void onStart() @@ -38,7 +37,12 @@ public class Trailer extends FreedomService return; } - if (!trailPlayers.contains(event.getPlayer().getName())) + if (!trailPlayers.contains(event.getPlayer().getUniqueId())) + { + return; + } + + if (!plugin.pl.getData(event.getPlayer()).hasItem(ShopItem.RAINBOW_TRAIL)) { return; } @@ -69,7 +73,7 @@ public class Trailer extends FreedomService { final Location trail_pos; trail_pos = new Location(event.getPlayer().getWorld(), fromBlock.getX() + x, fromBlock.getY(), fromBlock.getZ() + z); - if (trailPlayers.contains(event.getPlayer().getName()) && plugin.cpb.isEnabled()) + if (trailPlayers.contains(event.getPlayer().getUniqueId()) && plugin.cpb.isEnabled()) { plugin.cpb.getCoreProtectAPI().logPlacement(event.getPlayer().getName(), trail_pos, material, data); } @@ -79,16 +83,16 @@ public class Trailer extends FreedomService public void remove(Player player) { - trailPlayers.remove(player.getName()); + trailPlayers.remove(player.getUniqueId()); } public void add(Player player) { - trailPlayers.add(player.getName()); + trailPlayers.add(player.getUniqueId()); } public boolean contains(Player player) { - return trailPlayers.contains(player.getName()); + return trailPlayers.contains(player.getUniqueId()); } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java index 4ce94dd5..fe3bb097 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java @@ -10,19 +10,29 @@ public enum ShopItem LIGHTNING_ROD("Lightning Rod", Material.BLAZE_ROD, 12, ConfigEntry.SHOP_PRICES_LIGHTNING_ROD, ChatColor.LIGHT_PURPLE, "lightningRod", "/lightningrod"), FIRE_BALL("Fire Ball", Material.FIRE_CHARGE, 14, ConfigEntry.SHOP_PRICES_FIRE_BALL, ChatColor.RED, "fireBall", "/fireball"), RIDEABLE_PEARL("Rideable Ender Pearl", Material.ENDER_PEARL, 16, ConfigEntry.SHOP_PRICES_RIDEABLE_PEARL, ChatColor.DARK_PURPLE, "rideablePearl", "/rideablepearl"), - STACKING_POTATO("Stacking Potato", Material.POTATO, 20, ConfigEntry.SHOP_PRICES_STACKING_POTATO, ChatColor.YELLOW, "stackingPotato", "/stackingpotato"), - CLOWN_FISH("Clown Fish", Material.TROPICAL_FISH, 22, ConfigEntry.SHOP_PRICES_CLOWN_FISH, ChatColor.GOLD, "clownFish", "/clownfish"), - LOGIN_MESSAGES("Login Messages", Material.NAME_TAG, 24, ConfigEntry.SHOP_PRICES_LOGIN_MESSAGES, ChatColor.DARK_GREEN, "loginMessages", "/loginmessage"); + STACKING_POTATO("Stacking Potato", Material.POTATO, 19, ConfigEntry.SHOP_PRICES_STACKING_POTATO, ChatColor.YELLOW, "stackingPotato", "/stackingpotato"), + CLOWN_FISH("Clown Fish", Material.TROPICAL_FISH, 21, ConfigEntry.SHOP_PRICES_CLOWN_FISH, ChatColor.GOLD, "clownFish", "/clownfish"), + LOGIN_MESSAGES("Login Messages", Material.NAME_TAG, 23, ConfigEntry.SHOP_PRICES_LOGIN_MESSAGES, ChatColor.DARK_GREEN, "loginMessages", "/loginmessage"), + RAINBOW_TRAIL("Rainbow Trail", Material.RED_WOOL, 25, ConfigEntry.SHOP_PRICES_RAINBOW_TRAIL, ChatColor.DARK_RED, "rainbowTrail", "/trail"); /* Shop GUI Layout: Dimensions: 9x4 = 36 - Key: g = Grappling Hook, l = Lightning Rod, f = Fire Ball, r = Rideable Ender Pearl, s = Stacking Potato, c = Clown Fish, x = Login Messages $ = Coins} + Key: + g = Grappling Hook, + l = Lightning Rod + f = Fire Ball + r = Rideable Ender Pearl + s = Stacking Potato + c = Clown Fish + x = Login Messages + t = Rainbow Trail + $ = Coins --------- -g-l-f-r- - --s-c-x-- + -s-c-x-t- --------$ */ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1530fbfa..570d9965 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -159,6 +159,7 @@ shop: stacking_potato: 300 clown_fish: 1500 login_messages: 5000 + rainbow_trail: 1500 # Admin list adminlist: From f69feed469da5cb1852e96b68b742f261a3652ff Mon Sep 17 00:00:00 2001 From: Video Date: Mon, 6 Sep 2021 01:14:21 -0600 Subject: [PATCH 2/3] fixed --- .../java/me/totalfreedom/totalfreedommod/fun/Trailer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java index 382589e8..d4ddec7b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.fun; -import java.util.*; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; +import java.util.SplittableRandom; +import java.util.UUID; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.shop.ShopItem; @@ -17,7 +21,7 @@ import org.bukkit.event.player.PlayerMoveEvent; public class Trailer extends FreedomService { private final SplittableRandom random = new SplittableRandom(); - private final Set trailPlayers = new HashSet<>(); // player name + private final Set trailPlayers = new HashSet<>(); // player UUID @Override public void onStart() From 8356e831a5188b9bdae36e3672cd3d96919111c0 Mon Sep 17 00:00:00 2001 From: Video Date: Tue, 23 Nov 2021 09:11:16 -0700 Subject: [PATCH 3/3] Redundancy fix and better protection system --- .../bridge/WorldGuardBridge.java | 17 ++++++++++++ .../totalfreedommod/fun/Trailer.java | 27 ++++++++----------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java index 6bc0ab9b..ea03b670 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java @@ -1,13 +1,20 @@ package me.totalfreedom.totalfreedommod.bridge; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.RegionContainer; import java.util.Map; + +import com.sk89q.worldguard.protection.regions.RegionQuery; import me.totalfreedom.totalfreedommod.FreedomService; import org.bukkit.World; +import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; public class WorldGuardBridge extends FreedomService @@ -23,6 +30,16 @@ public class WorldGuardBridge extends FreedomService { } + public boolean canEditCurrentWorld(Player player) + { + LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); + + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = container.createQuery(); + + return query.testBuild(localPlayer.getLocation(), localPlayer); + } + public RegionManager getRegionManager(World world) { RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java index d4ddec7b..e603b242 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java @@ -36,22 +36,17 @@ public class Trailer extends FreedomService @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { - if (trailPlayers.isEmpty()) - { - return; - } - - if (!trailPlayers.contains(event.getPlayer().getUniqueId())) - { - return; - } - - if (!plugin.pl.getData(event.getPlayer()).hasItem(ShopItem.RAINBOW_TRAIL)) - { - return; - } - - if (event.getPlayer().getWorld().equals(plugin.wm.masterBuilderWorld.getWorld())) + /* Doesn't continue any further if... + * - The trail list is empty + * - The player doesn't have their trail enabled in the first place + * - The player doesn't have the trail item in the shop at all + * - The player doesn't have permission to modify blocks in their current world + */ + if (trailPlayers.isEmpty() + || !trailPlayers.contains(event.getPlayer().getUniqueId()) + || !plugin.pl.getData(event.getPlayer()).hasItem(ShopItem.RAINBOW_TRAIL) + || plugin.wr.doRestrict(event.getPlayer()) + || !plugin.wgb.canEditCurrentWorld(event.getPlayer())) { return; }