From 3a3b450921752db5df90104d5380454d971ecac2 Mon Sep 17 00:00:00 2001 From: mathiascode Date: Sun, 1 Dec 2019 01:04:08 +0200 Subject: [PATCH] Don't hardcode join titles --- src/main/java/pw/kaboom/extras/Main.java | 2 ++ .../kaboom/extras/commands/CommandPrefix.java | 35 ++++++++++++------- .../extras/modules/block/BlockPhysics.java | 19 +++++++--- .../extras/modules/player/PlayerChat.java | 11 ++++-- .../modules/player/PlayerConnection.java | 19 ++++++---- src/main/resources/config.yml | 2 ++ 6 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 src/main/resources/config.yml diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index 926ea95..cf549cf 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -650,6 +650,8 @@ public class Main extends JavaPlugin { this.nonSolidBlockList.addAll(nonSolidDoubleBlockList); this.nonSolidBlockList.addAll(nonSolidSingularBlockList); this.nonSolidBlockList.addAll(nonSolidWallMountedBlockList); + + saveResource("config.yml", false); } public void onEnable() { diff --git a/src/main/java/pw/kaboom/extras/commands/CommandPrefix.java b/src/main/java/pw/kaboom/extras/commands/CommandPrefix.java index 0cce297..da898c8 100644 --- a/src/main/java/pw/kaboom/extras/commands/CommandPrefix.java +++ b/src/main/java/pw/kaboom/extras/commands/CommandPrefix.java @@ -1,5 +1,7 @@ package pw.kaboom.extras; +import java.io.File; + import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -7,6 +9,9 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -17,18 +22,24 @@ class CommandPrefix implements CommandExecutor { sender.sendMessage("Command has to be run by a player"); } else { final Player player = (Player) sender; - final JavaPlugin plugin = JavaPlugin.getPlugin(Main.class); - - if (args.length == 0) { - player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); - } else if (args[0].equalsIgnoreCase("off")) { - plugin.getConfig().set(player.getUniqueId().toString(), null); - plugin.saveConfig(); - player.sendMessage("You no longer have a tag"); - } else { - plugin.getConfig().set(player.getUniqueId().toString(), String.join(" ", args)); - plugin.saveConfig(); - player.sendMessage("You now have the tag: " + ChatColor.translateAlternateColorCodes('&', String.join(" ", args))); + final File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder(), "prefixes.yml"); + final FileConfiguration prefixConfig = YamlConfiguration.loadConfiguration(configFile); + + try { + if (args.length == 0) { + player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + } else if (args[0].equalsIgnoreCase("off")) { + prefixConfig.set(player.getUniqueId().toString(), null); + prefixConfig.save(configFile); + player.sendMessage("You no longer have a tag"); + } else { + prefixConfig.set(player.getUniqueId().toString(), String.join(" ", args)); + prefixConfig.save(configFile); + player.sendMessage("You now have the tag: " + ChatColor.translateAlternateColorCodes('&', String.join(" ", args))); + } + } catch (Exception exception) { + player.sendMessage("Something went wrong while saving the prefix. Please check console."); + exception.printStackTrace(); } } return true; diff --git a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java index c8bd3f1..d58482b 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java @@ -5,12 +5,13 @@ import java.util.ArrayList; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Nameable; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; import org.bukkit.block.CommandBlock; -import org.bukkit.block.ShulkerBox; import org.bukkit.block.data.Levelled; @@ -73,13 +74,21 @@ class BlockPhysics implements Listener { @EventHandler void onBlockPhysics(BlockPhysicsEvent event) { final Material material = event.getChangedType(); + final BlockState blockState = event.getSourceBlock().getState(); + final BlockState blockStateSource = event.getSourceBlock().getState(); + + /*if (event.getSourceBlock().getBlockData().getAsString().length() > 3019) { + event.getSourceBlock().setType(Material.AIR); + } else if (event.getBlock().getBlockData().getAsString().length() > 3019) { + event.getBlock().setType(Material.AIR); + }*/ if (material == Material.FARMLAND) { event.setCancelled(true); - } else if (event.getSourceBlock().getState() instanceof CommandBlock) { - event.getSourceBlock().getState().update(); - } else if (event.getBlock().getState() instanceof CommandBlock) { - event.getBlock().getState().update(); + } else if (blockState instanceof CommandBlock) { + blockState.update(); + } else if (blockStateSource instanceof CommandBlock) { + blockStateSource.update(); } else if (event.getBlock().isLiquid()) { final Block block = event.getBlock(); final World world = block.getWorld(); diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java index 9e07508..7df6695 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java @@ -1,9 +1,13 @@ package pw.kaboom.extras; +import java.io.File; import java.util.UUID; import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -32,11 +36,14 @@ class PlayerChat implements Listener { if (event.isCancelled()) { return; } + + final File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder(), "prefixes.yml"); + final FileConfiguration prefixConfig = YamlConfiguration.loadConfiguration(configFile); - if (JavaPlugin.getPlugin(Main.class).getConfig().getString(player.getUniqueId().toString()) != null) { + if (prefixConfig.getString(player.getUniqueId().toString()) != null) { final String prefix = ChatColor.translateAlternateColorCodes( '&', - JavaPlugin.getPlugin(Main.class).getConfig().getString(player.getUniqueId().toString()) + prefixConfig.getString(player.getUniqueId().toString()) ); event.setFormat(prefix + ChatColor.RESET + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s"); diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index 77dc55b..0896de1 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -62,6 +62,8 @@ class PlayerConnection implements Listener { @EventHandler void onPlayerJoin(PlayerJoinEvent event) { final Player player = event.getPlayer(); + final String title = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinTitle"); + final String subtitle = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinSubtitle"); final int fadeIn = 10; final int stay = 160; final int fadeOut = 5; @@ -87,13 +89,16 @@ class PlayerConnection implements Listener { } } - player.sendTitle( - ChatColor.GRAY + "Welcome to Kaboom!", - "Free OP • Anarchy • Creative", - fadeIn, - stay, - fadeOut - ); + if (title != null || + subtitle != null) { + player.sendTitle( + title, + subtitle, + fadeIn, + stay, + fadeOut + ); + } } @EventHandler diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..cf9d344 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,2 @@ +playerJoinTitle: "§7Welcome to Kaboom!" +playerJoinSubtitle: "Free OP • Anarchy • Creative"