From 668488dfd11dc7535e96f9b55e3a414965c52fd0 Mon Sep 17 00:00:00 2001 From: Super_ Date: Sun, 1 Nov 2020 19:06:08 -0500 Subject: [PATCH] freezing, yml messages, and a funny lil command --- src/main/java/me/totalfreedom/plex/Plex.java | 9 +- .../totalfreedom/plex/cache/PlayerCache.java | 11 +- .../plex/command/PlexCommand.java | 6 +- .../annotations/CommandPermissions.java | 2 +- .../plex/command/impl/FionnCMD.java | 133 ++++++++++++++++++ .../plex/command/impl/TestCMD.java | 9 +- .../plex/command/impl/WorldCMD.java | 50 +++++++ .../plex/handlers/CommandHandler.java | 4 + .../plex/handlers/ListenerHandler.java | 2 + .../plex/listener/impl/FreezeListener.java | 18 +++ .../plex/listener/impl/PlayerListener.java | 20 +++ .../plex/listener/impl/WorldListener.java | 19 ++- .../plex/message/MessageManager.java | 70 --------- .../totalfreedom/plex/player/PlexPlayer.java | 4 + .../totalfreedom/plex/rank/RankManager.java | 2 +- .../me/totalfreedom/plex/rank/enums/Rank.java | 2 +- .../me/totalfreedom/plex/util/PlexUtils.java | 60 +++++++- .../plex/world/BlockMapChunkGenerator.java | 34 +++++ .../world/ConfigurationChunkGenerator.java | 23 +-- .../totalfreedom/plex/world/CustomWorld.java | 2 +- src/main/resources/messages.yml | 22 +++ 21 files changed, 391 insertions(+), 111 deletions(-) create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/WorldCMD.java create mode 100644 src/main/java/me/totalfreedom/plex/listener/impl/FreezeListener.java delete mode 100644 src/main/java/me/totalfreedom/plex/message/MessageManager.java create mode 100644 src/main/java/me/totalfreedom/plex/world/BlockMapChunkGenerator.java create mode 100644 src/main/resources/messages.yml diff --git a/src/main/java/me/totalfreedom/plex/Plex.java b/src/main/java/me/totalfreedom/plex/Plex.java index 05698a2..f15fc6c 100644 --- a/src/main/java/me/totalfreedom/plex/Plex.java +++ b/src/main/java/me/totalfreedom/plex/Plex.java @@ -7,7 +7,6 @@ import me.totalfreedom.plex.cache.SQLPlayerData; import me.totalfreedom.plex.config.Config; import me.totalfreedom.plex.handlers.CommandHandler; import me.totalfreedom.plex.handlers.ListenerHandler; -import me.totalfreedom.plex.message.MessageManager; import me.totalfreedom.plex.rank.RankManager; import me.totalfreedom.plex.storage.MongoConnection; import me.totalfreedom.plex.storage.RedisConnection; @@ -24,6 +23,7 @@ public class Plex extends JavaPlugin { private static Plex plugin; public Config config; + public Config messages; private StorageType storageType = StorageType.SQLITE; private SQLConnection sqlConnection; @@ -34,7 +34,6 @@ public class Plex extends JavaPlugin private SQLPlayerData sqlPlayerData; private RankManager rankManager; - private MessageManager messageManager; public static Plex get() { @@ -46,6 +45,7 @@ public class Plex extends JavaPlugin { plugin = this; config = new Config(this, "config.yml"); + messages = new Config(this, "messages.yml"); saveResource("database.db", false); sqlConnection = new SQLConnection(); @@ -64,6 +64,7 @@ public class Plex extends JavaPlugin public void onEnable() { config.load(); + messages.load(); try { @@ -93,10 +94,6 @@ public class Plex extends JavaPlugin rankManager.importDefaultRanks(); PlexLog.log("Rank Manager initialized"); - messageManager = new MessageManager(); - messageManager.generateMessages(); - PlexLog.log("Message Manager initialized"); - generateWorlds(); } diff --git a/src/main/java/me/totalfreedom/plex/cache/PlayerCache.java b/src/main/java/me/totalfreedom/plex/cache/PlayerCache.java index 4bce5d3..be3bda9 100644 --- a/src/main/java/me/totalfreedom/plex/cache/PlayerCache.java +++ b/src/main/java/me/totalfreedom/plex/cache/PlayerCache.java @@ -20,5 +20,14 @@ public class PlayerCache { return plexPlayerMap; } - + + public static PunishedPlayer getPunishedPlayer(UUID uuid) + { + return getPunishedPlayerMap().get(uuid); + } + + public static PlexPlayer getPlexPlayer(UUID uuid) + { + return getPlexPlayerMap().get(uuid); + } } diff --git a/src/main/java/me/totalfreedom/plex/command/PlexCommand.java b/src/main/java/me/totalfreedom/plex/command/PlexCommand.java index ff3598a..04a2af0 100644 --- a/src/main/java/me/totalfreedom/plex/command/PlexCommand.java +++ b/src/main/java/me/totalfreedom/plex/command/PlexCommand.java @@ -76,7 +76,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC Player player = (Player) sender; PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); - if (!plexPlayer.getRankFromString().isAtleast(getLevel())) + if (!plexPlayer.getRankFromString().isAtLeast(getLevel())) { //TODO: Enter only and higher msg return true; @@ -91,7 +91,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC } else { Player player = (Player) sender; PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); - if (!plexPlayer.getRankFromString().isAtleast(getLevel())) + if (!plexPlayer.getRankFromString().isAtLeast(getLevel())) { //TODO: Enter only and higher msg return true; @@ -111,7 +111,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC { Player player = (Player) sender; PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); - if (plexPlayer.getRankFromString().isAtleast(getLevel())) + if (plexPlayer.getRankFromString().isAtLeast(getLevel())) { return onTabComplete(sender, args); } else { diff --git a/src/main/java/me/totalfreedom/plex/command/annotations/CommandPermissions.java b/src/main/java/me/totalfreedom/plex/command/annotations/CommandPermissions.java index 4f64503..d212d2c 100644 --- a/src/main/java/me/totalfreedom/plex/command/annotations/CommandPermissions.java +++ b/src/main/java/me/totalfreedom/plex/command/annotations/CommandPermissions.java @@ -10,5 +10,5 @@ import java.lang.annotation.RetentionPolicy; public @interface CommandPermissions { Rank level() default Rank.IMPOSTOR; - RequiredCommandSource source(); + RequiredCommandSource source() default RequiredCommandSource.ANY; } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java new file mode 100644 index 0000000..4bf7a9d --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java @@ -0,0 +1,133 @@ +package me.totalfreedom.plex.command.impl; + +import me.totalfreedom.plex.cache.PlayerCache; +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotations.CommandParameters; +import me.totalfreedom.plex.command.annotations.CommandPermissions; +import me.totalfreedom.plex.command.source.RequiredCommandSource; +import me.totalfreedom.plex.util.PlexUtils; +import me.totalfreedom.plex.world.BlockMapChunkGenerator; +import me.totalfreedom.plex.world.CustomWorld; +import org.bukkit.*; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.*; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.*; + +@CommandParameters(description = "Subliminal message.") +@CommandPermissions(source = RequiredCommandSource.IN_GAME) +public class FionnCMD extends PlexCommand +{ + public static boolean ENABLED = false; + public static Map LOCATION_CACHE = new HashMap<>(); + + public FionnCMD() + { + super("fionn"); + } + + @Override + public void execute(CommandSender sender, String[] args) + { + Player player = (Player) sender; + if (!player.getUniqueId().equals(UUID.fromString("9aa3eda6-c271-440a-a578-a952ee9aee2f"))) + { + sender.sendMessage(ChatColor.RED + "You cannot run this command!"); + return; + } + String name = "fionn"; + LinkedHashMap map = new LinkedHashMap<>(); + map.put(Material.CRIMSON_NYLIUM, 1); + map.put(Material.BEDROCK, 1); + World fionnWorld = new CustomWorld(name, new BlockMapChunkGenerator(map)).generate(); + ENABLED = true; + fionnWorld.setTime(0); + fionnWorld.getBlockAt(0, 5, 0).setType(Material.BARRIER); + Strider fionn = (Strider) fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 6, -180, -3), EntityType.STRIDER); + fionn.setCustomNameVisible(true); + fionn.setCustomName(ChatColor.GREEN + "fionn"); + fionn.setAI(false); + Enderman elmon = (Enderman) fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 0, 0, 18), EntityType.ENDERMAN); + elmon.setCustomNameVisible(true); + elmon.setCustomName(ChatColor.RED + "elmon"); + elmon.setInvulnerable(true); + elmon.setAware(false); + elmon.setGravity(true); + // platforms in cage + PlexUtils.setBlocks(new Location(fionnWorld, 10, 5, -2), new Location(fionnWorld, 14, 5, 2), Material.SMOOTH_STONE); + PlexUtils.setBlocks(new Location(fionnWorld, 10, 9, -2), new Location(fionnWorld, 14, 9, 2), Material.SMOOTH_STONE_SLAB); + // iron bars of cage + PlexUtils.setBlocks(new Location(fionnWorld, 10, 8, -2), new Location(fionnWorld, 10, 6, 2), Material.IRON_BARS); + PlexUtils.setBlocks(new Location(fionnWorld, 14, 8, 2), new Location(fionnWorld, 10, 6, 2), Material.IRON_BARS); + PlexUtils.setBlocks(new Location(fionnWorld, 14, 8, 2), new Location(fionnWorld, 14, 6, -2), Material.IRON_BARS); + PlexUtils.setBlocks(new Location(fionnWorld, 10, 8, -2), new Location(fionnWorld, 14, 6, -2), Material.IRON_BARS); + // lava + PlexUtils.setBlocks(new Location(fionnWorld, 10, 1, -2), new Location(fionnWorld, 14, 0, 2), Material.LAVA); + + // iron bars of platform + PlexUtils.setBlocks(new Location(fionnWorld, 12, 2, 6), new Location(fionnWorld, 12, 5, 6), Material.IRON_BARS); + // platform + PlexUtils.setBlocks(new Location(fionnWorld, 11, 6, 7), new Location(fionnWorld, 13, 6, 5), Material.SMOOTH_STONE_SLAB); + for (Player p : Bukkit.getOnlinePlayers()) + { + p.setInvisible(true); + LOCATION_CACHE.put(p, p.getLocation()); + p.teleport(new Location(fionnWorld, 0, 5, 0, -90, 0)); + PlayerCache.getPlexPlayer(p.getUniqueId()).setFrozen(true); + } + lateFakeChat("elmon", "fionn! i'm sorry for not being your sex slave...", ChatColor.RED, 20); + lateFakeChat("fionn", "it's too late for that now...", ChatColor.GREEN, 60); + new BukkitRunnable() + { + @Override + public void run() + { + PlexUtils.setBlocks(new Location(fionnWorld, 13, 5, -1), new Location(fionnWorld, 11, 5, 1), Material.AIR); + } + }.runTaskLater(plugin, 100); + new BukkitRunnable() + { + @Override + public void run() + { + fionn.teleport(new Location(fionnWorld, 2.5, 5.5, 0, 90, -10)); + } + }.runTaskLater(plugin, 160); + new BukkitRunnable() + { + public void run() + { + fionn.remove(); + elmon.remove(); + for (Player p : Bukkit.getOnlinePlayers()) + { + p.setInvisible(false); + Location location = LOCATION_CACHE.get(p); + if (location != null) + p.teleport(location); + PlayerCache.getPlexPlayer(p.getUniqueId()).setFrozen(false); + } + LOCATION_CACHE.clear(); + ENABLED = false; + } + }.runTaskLater(plugin, 200); + } + + @Override + public List onTabComplete(CommandSender sender, String[] args) + { + return null; + } + + public static void lateFakeChat(String name, String message, ChatColor color, int delay) + { + new BukkitRunnable() + { + public void run() + { + Bukkit.broadcastMessage(color + name + ChatColor.GRAY + ": " + ChatColor.WHITE + message); + } + }.runTaskLater(plugin, delay); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/TestCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/TestCMD.java index 5a5052f..e5b3ed9 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/TestCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/TestCMD.java @@ -11,8 +11,10 @@ import org.bukkit.command.CommandSender; import java.util.Arrays; import java.util.List; +import static me.totalfreedom.plex.util.PlexUtils.tl; + @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY) -@CommandParameters(usage = "/", aliases = "tst,tast", description = "HELLO") +@CommandParameters(aliases = "tst,tast", description = "HELLO") public class TestCMD extends PlexCommand { public TestCMD() { @@ -20,8 +22,9 @@ public class TestCMD extends PlexCommand } @Override - public void execute(CommandSender sender, String[] args) { - sender.sendMessage(plugin.getMessageManager().getMessage("test")); + public void execute(CommandSender sender, String[] args) + { + sender.sendMessage(tl("variableTest", sender.getName())); } @Override diff --git a/src/main/java/me/totalfreedom/plex/command/impl/WorldCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/WorldCMD.java new file mode 100644 index 0000000..e9eb256 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/WorldCMD.java @@ -0,0 +1,50 @@ +package me.totalfreedom.plex.command.impl; + +import com.google.common.collect.ImmutableList; +import me.totalfreedom.plex.Plex; +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotations.CommandParameters; +import me.totalfreedom.plex.command.annotations.CommandPermissions; +import me.totalfreedom.plex.command.source.RequiredCommandSource; +import me.totalfreedom.plex.rank.enums.Rank; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static me.totalfreedom.plex.util.PlexUtils.tl; + +@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME) +@CommandParameters(description = "Teleport to a world.", usage = "/ ") +public class WorldCMD extends PlexCommand +{ + public WorldCMD() { + super("world"); + } + + @Override + public void execute(CommandSender sender, String[] args) + { + Player player = (Player) sender; + World world = Bukkit.getWorld(args[0]); + player.teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0)); + sender.sendMessage(tl("playerWorldTeleport", world.getName())); + } + + @Override + public List onTabComplete(CommandSender sender, String[] args) + { + List worlds = new ArrayList<>(); + for (World world : Bukkit.getWorlds()) + worlds.add(world.getName()); + if (args.length == 1) + return worlds; + return ImmutableList.of(); + } + +} diff --git a/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java b/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java index b63ca27..1e479ae 100644 --- a/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java +++ b/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java @@ -2,8 +2,10 @@ package me.totalfreedom.plex.handlers; import com.google.common.collect.Lists; import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.impl.FionnCMD; import me.totalfreedom.plex.command.impl.PlexCMD; import me.totalfreedom.plex.command.impl.TestCMD; +import me.totalfreedom.plex.command.impl.WorldCMD; import me.totalfreedom.plex.util.PlexLog; import java.util.List; @@ -17,6 +19,8 @@ public class CommandHandler { commands.add(new TestCMD()); commands.add(new PlexCMD()); + commands.add(new FionnCMD()); + commands.add(new WorldCMD()); PlexLog.log(String.format("Registered %s commands!", commands.size())); } diff --git a/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java b/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java index a2c8e8d..8d3fe5a 100644 --- a/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java +++ b/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java @@ -3,6 +3,7 @@ package me.totalfreedom.plex.handlers; import com.google.common.collect.Lists; import me.totalfreedom.plex.listener.PlexListener; import me.totalfreedom.plex.listener.impl.ChatListener; +import me.totalfreedom.plex.listener.impl.FreezeListener; import me.totalfreedom.plex.listener.impl.PlayerListener; import me.totalfreedom.plex.listener.impl.WorldListener; import me.totalfreedom.plex.util.PlexLog; @@ -19,6 +20,7 @@ public class ListenerHandler listeners.add(new ChatListener()); listeners.add(new PlayerListener()); listeners.add(new WorldListener()); + listeners.add(new FreezeListener()); PlexLog.log(String.format("Registered %s listeners!", listeners.size())); } diff --git a/src/main/java/me/totalfreedom/plex/listener/impl/FreezeListener.java b/src/main/java/me/totalfreedom/plex/listener/impl/FreezeListener.java new file mode 100644 index 0000000..ba21f99 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/listener/impl/FreezeListener.java @@ -0,0 +1,18 @@ +package me.totalfreedom.plex.listener.impl; + +import me.totalfreedom.plex.cache.PlayerCache; +import me.totalfreedom.plex.listener.PlexListener; +import me.totalfreedom.plex.player.PlexPlayer; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; + +public class FreezeListener extends PlexListener +{ + @EventHandler + public void onPlayerMove(PlayerMoveEvent e) + { + PlexPlayer player = PlayerCache.getPlexPlayer(e.getPlayer().getUniqueId()); + if (player.isFrozen()) + e.setCancelled(true); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/listener/impl/PlayerListener.java b/src/main/java/me/totalfreedom/plex/listener/impl/PlayerListener.java index 1273c04..43fa294 100644 --- a/src/main/java/me/totalfreedom/plex/listener/impl/PlayerListener.java +++ b/src/main/java/me/totalfreedom/plex/listener/impl/PlayerListener.java @@ -5,11 +5,13 @@ import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.cache.MongoPlayerData; import me.totalfreedom.plex.cache.PlayerCache; import me.totalfreedom.plex.cache.SQLPlayerData; +import me.totalfreedom.plex.command.impl.FionnCMD; import me.totalfreedom.plex.listener.PlexListener; import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PunishedPlayer; import me.totalfreedom.plex.util.PlexLog; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -22,6 +24,7 @@ public class PlayerListener extends PlexListener private final MongoPlayerData mongoPlayerData = plugin.getMongoPlayerData() != null ? plugin.getMongoPlayerData() : null; private final SQLPlayerData sqlPlayerData = plugin.getSqlPlayerData() != null ? plugin.getSqlPlayerData() : null; + // setting up a player's data @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerSetup(PlayerJoinEvent event) { @@ -80,6 +83,7 @@ public class PlayerListener extends PlexListener } } + // saving the player's data @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerSave(PlayerQuitEvent event) { @@ -98,4 +102,20 @@ public class PlayerListener extends PlexListener PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId()); } + // unrelated player quitting + @EventHandler + public void onPlayerQuit(PlayerQuitEvent e) + { + Player player = e.getPlayer(); + PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(player.getUniqueId()); + + if (FionnCMD.ENABLED) + { + player.setInvisible(false); + plexPlayer.setFrozen(false); + Location location = FionnCMD.LOCATION_CACHE.get(player); + if (location != null) + player.teleport(location); + } + } } diff --git a/src/main/java/me/totalfreedom/plex/listener/impl/WorldListener.java b/src/main/java/me/totalfreedom/plex/listener/impl/WorldListener.java index e49cd0c..004c9bc 100644 --- a/src/main/java/me/totalfreedom/plex/listener/impl/WorldListener.java +++ b/src/main/java/me/totalfreedom/plex/listener/impl/WorldListener.java @@ -4,11 +4,14 @@ import me.totalfreedom.plex.cache.PlayerCache; import me.totalfreedom.plex.listener.PlexListener; import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.rank.enums.Rank; -import me.totalfreedom.plex.util.PlexUtils; import org.bukkit.World; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntitySpawnEvent; + +import static me.totalfreedom.plex.util.PlexUtils.tl; public class WorldListener extends PlexListener { @@ -22,12 +25,22 @@ public class WorldListener extends PlexListener { case "adminworld": { - if (plexPlayer.getRankFromString().isAtleast(Rank.ADMIN)) + if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN)) return; e.setCancelled(true); - player.sendMessage(PlexUtils.color(plugin.getMessageManager().getMessage("noAdminWorldBlockPlace"))); + player.sendMessage(tl("noAdminWorldBlockPlace")); break; } } } + + @EventHandler + public void onEntitySpawn(EntitySpawnEvent e) + { + if (!e.getLocation().getWorld().getName().equals("fionn")) + return; + if (e.getEntityType() != EntityType.SLIME) + return; + e.setCancelled(true); + } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/message/MessageManager.java b/src/main/java/me/totalfreedom/plex/message/MessageManager.java deleted file mode 100644 index 60a5b84..0000000 --- a/src/main/java/me/totalfreedom/plex/message/MessageManager.java +++ /dev/null @@ -1,70 +0,0 @@ -package me.totalfreedom.plex.message; - -import me.totalfreedom.plex.Plex; -import me.totalfreedom.plex.util.PlexLog; -import org.json.JSONObject; -import org.json.JSONTokener; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; - -public class MessageManager -{ - private final File messages; - - public MessageManager() - { - this.messages = new File(Plex.get().getDataFolder(), "messages.json"); - } - - public void generateMessages() - { - if (messages.exists()) - { - return; - } - try - { - messages.createNewFile(); - - JSONObject obj = new JSONObject(); - if (obj.length() == 0) - { - obj.put("test", "this is a test message!"); - obj.put("noAdminWorldBlockPlace", "&cYou are not allowed to place blocks in the admin world!"); - obj.put("noAdminWorldBlockBreak", "&cYou are not allowed to break blocks in the admin world!"); - FileWriter writer = new FileWriter(messages); - writer.append(obj.toString(4)); - writer.flush(); - writer.close(); - PlexLog.log("Generating messages.json"); - } - } - catch (IOException e) - { - e.printStackTrace(); - } - } - - public String getMessage(String s) - { - if (!messages.exists()) - return null; - - try - { - FileInputStream stream = new FileInputStream(messages); - JSONTokener tokener = new JSONTokener(stream); - JSONObject object = new JSONObject(tokener); - return (String) object.get(s); - } - catch (IOException e) - { - e.printStackTrace(); - } - - return null; - } -} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/player/PlexPlayer.java b/src/main/java/me/totalfreedom/plex/player/PlexPlayer.java index 0f23062..d53a13b 100644 --- a/src/main/java/me/totalfreedom/plex/player/PlexPlayer.java +++ b/src/main/java/me/totalfreedom/plex/player/PlexPlayer.java @@ -39,6 +39,8 @@ public class PlexPlayer private List ips; + private boolean frozen; + public PlexPlayer() {} public PlexPlayer(UUID playerUUID) @@ -57,6 +59,8 @@ public class PlexPlayer this.ips = new ArrayList<>(); this.rank = ""; + + this.frozen = false; } public Rank getRankFromString() diff --git a/src/main/java/me/totalfreedom/plex/rank/RankManager.java b/src/main/java/me/totalfreedom/plex/rank/RankManager.java index 4388b48..fca8fcd 100644 --- a/src/main/java/me/totalfreedom/plex/rank/RankManager.java +++ b/src/main/java/me/totalfreedom/plex/rank/RankManager.java @@ -95,6 +95,6 @@ public class RankManager public boolean isAdmin(PlexPlayer plexPlayer) { - return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtleast(Rank.ADMIN); + return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN); } } diff --git a/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java b/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java index 30cefe3..7620ecb 100644 --- a/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java +++ b/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java @@ -50,7 +50,7 @@ public enum Rank this.prefix = prefix; } - public boolean isAtleast(Rank rank) + public boolean isAtLeast(Rank rank) { return getLevel() >= rank.getLevel(); } diff --git a/src/main/java/me/totalfreedom/plex/util/PlexUtils.java b/src/main/java/me/totalfreedom/plex/util/PlexUtils.java index fa119be..20c97de 100644 --- a/src/main/java/me/totalfreedom/plex/util/PlexUtils.java +++ b/src/main/java/me/totalfreedom/plex/util/PlexUtils.java @@ -2,14 +2,13 @@ package me.totalfreedom.plex.util; import java.sql.SQLException; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import me.totalfreedom.plex.Plex; +import me.totalfreedom.plex.config.Config; import me.totalfreedom.plex.storage.StorageType; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.command.Command; import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.entity.Player; @@ -68,8 +67,61 @@ public class PlexUtils return ChatColor.translateAlternateColorCodes('&', s); } + // if you think the name of this method is dumb feel free to change it i just thought it'd be cool + public static String tl(String s, Object... objects) + { + Plex plugin = Plex.get(); + if (s.equals("baseColor") || s.equals("errorColor")) + return getChatColorFromConfig(plugin.messages, (s.equals("baseColor") ? ChatColor.GRAY : ChatColor.RED), s).toString(); + String f = plugin.messages.getString(s); + if (f == null) + return ChatColor.RED + "No message"; + for (Object object : objects) + f = f.replace("", String.valueOf(object)); + ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor"); + ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor"); + f = f.replaceAll("", base.toString()); + f = f.replaceAll("", error.toString()); + return base + f; + } + + public static ChatColor getChatColorFromConfig(Config config, ChatColor def, String path) + { + ChatColor color; + if (config.getString(path) == null) + color = def; + else if (ChatColor.getByChar(config.getString(path)) == null) + color = def; + else + color = ChatColor.getByChar(config.getString(path)); + return color; + } + public static void warpToWorld(Player player, World world) { player.teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0), 0)); } + + public static void setBlocks(Location c1, Location c2, Material material) + { + if (!c1.getWorld().getName().equals(c1.getWorld().getName())) + return; + int sy = Math.min(c1.getBlockY(), c2.getBlockY()), + ey = Math.max(c1.getBlockY(), c2.getBlockY()), + sx = Math.min(c1.getBlockX(), c2.getBlockX()), + ex = Math.max(c1.getBlockX(), c2.getBlockX()), + sz = Math.min(c1.getBlockZ(), c2.getBlockZ()), + ez = Math.max(c1.getBlockZ(), c2.getBlockZ()); + World world = c1.getWorld(); + for (int y = sy; y <= ey; y++) + { + for (int x = sx; x <= ex; x++) + { + for (int z = sz; z <= ez; z++) + { + world.getBlockAt(x, y, z).setType(material); + } + } + } + } } diff --git a/src/main/java/me/totalfreedom/plex/world/BlockMapChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/BlockMapChunkGenerator.java new file mode 100644 index 0000000..b6f2792 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/BlockMapChunkGenerator.java @@ -0,0 +1,34 @@ +package me.totalfreedom.plex.world; + +import me.totalfreedom.plex.Plex; +import org.bukkit.Material; +import org.bukkit.generator.BlockPopulator; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class BlockMapChunkGenerator extends FlatChunkGenerator +{ + private static Plex plugin = Plex.get(); + + protected LinkedHashMap blockMap; + + public BlockMapChunkGenerator(LinkedHashMap blockMap, BlockPopulator... populators) + { + super(0, populators); + this.blockMap = blockMap; + } + + @Override + public void createLoopChunkData(int x, int y, int z, ChunkData chunk) + { + int height = -1; + for (int i : blockMap.values()) + height += i; + for (Map.Entry entry : blockMap.entrySet()) + { + for (int i = 0; i < entry.getValue(); i++, height--) + chunk.setBlock(x, height, z, entry.getKey()); + } + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/ConfigurationChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/ConfigurationChunkGenerator.java index ea7d930..8bf841b 100644 --- a/src/main/java/me/totalfreedom/plex/world/ConfigurationChunkGenerator.java +++ b/src/main/java/me/totalfreedom/plex/world/ConfigurationChunkGenerator.java @@ -5,37 +5,26 @@ import org.bukkit.Material; import org.bukkit.generator.BlockPopulator; import java.util.LinkedHashMap; -import java.util.Map; -public class ConfigurationChunkGenerator extends FlatChunkGenerator +public class ConfigurationChunkGenerator extends BlockMapChunkGenerator { private static Plex plugin = Plex.get(); - private final String worldName; - public ConfigurationChunkGenerator(String worldName, BlockPopulator... populators) { - super(0, populators); - this.worldName = worldName; + super(createBlockMap(worldName), populators); } - @Override - public void createLoopChunkData(int x, int y, int z, ChunkData chunk) + private static LinkedHashMap createBlockMap(String worldName) { - int height = -1; - Map blocks = new LinkedHashMap<>(); + LinkedHashMap blockMap = new LinkedHashMap<>(); for (String key : plugin.config.getConfigurationSection("worlds." + worldName + ".parameters").getKeys(false)) { Material material = Material.getMaterial(key.toUpperCase()); if (material == null) continue; int count = plugin.config.getInt("worlds." + worldName + ".parameters." + key); - height += count; - blocks.put(material, count); - } - for (Map.Entry entry : blocks.entrySet()) - { - for (int i = 0; i < entry.getValue(); i++, height--) - chunk.setBlock(x, height, z, entry.getKey()); + blockMap.put(material, count); } + return blockMap; } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/CustomWorld.java b/src/main/java/me/totalfreedom/plex/world/CustomWorld.java index c762bf8..8f7c45c 100644 --- a/src/main/java/me/totalfreedom/plex/world/CustomWorld.java +++ b/src/main/java/me/totalfreedom/plex/world/CustomWorld.java @@ -18,7 +18,7 @@ public class CustomWorld extends WorldCreator private final CustomChunkGenerator chunks; - private CustomWorld(String name, CustomChunkGenerator generator) + public CustomWorld(String name, CustomChunkGenerator generator) { super(name); this.chunks = generator; diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml new file mode 100644 index 0000000..a759a00 --- /dev/null +++ b/src/main/resources/messages.yml @@ -0,0 +1,22 @@ +# Plex Messages File + +# Messages in here will be placed in for certain commands, actions, etc. +# Warning: not all commands have customizable messages + +# Base color - the main color prefix; will be used following each of the messages below +# Error color - the color of an error; will be used when an error is thrown from a command +baseColor: "7" +errorColor: "c" + +# Variables - these are code-defined replacements for things that should be inserted into messages. (e.g. names, statuses, numbers) +# if any of these variables are defined within a message, some documentation is provided to give more context to what the variables indicate. +# message variables are used in numerical order that is unchangeable from this file. + +# Reset color - this will reset the color of the message to the base color defined above. +# Error color - this will make the color of the message the error color defined above. + +test: this is a test message! +variableTest: variable test with ! +noAdminWorldBlockPlace: You are not allowed to place blocks in the admin world! +noAdminWorldBlockBreak: You are not allowed to break blocks in the admin world! +playerWorldTeleport: You have been teleported to . \ No newline at end of file