From 7e194171e8f56f5a271000766223c5329a8fe663 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 7 May 2020 17:46:50 +0200 Subject: [PATCH] refactor: use this. use final and only use getters and setters --- .../main/java/de/cliffbreak/varo/Varo.java | 121 ++++++++---------- .../cliffbreak/varo/commands/VaroCommand.java | 27 ++-- .../varo/listeners/BannedActionListener.java | 2 +- .../varo/listeners/BannedItemListener.java | 10 +- .../varo/listeners/ChatListener.java | 2 +- .../varo/listeners/CreatureSpawnListener.java | 28 ---- .../listeners/EntityRegainHealthListener.java | 2 +- .../PlayerClientOptionsChangeListener.java | 12 +- .../varo/listeners/PlayerDeathListener.java | 9 +- .../listeners/PlayerInteractNPCListener.java | 9 +- .../listeners/PlayerJoinQuitListener.java | 14 +- .../listeners/PlayerPreLoginListener.java | 2 +- .../cliffbreak/varo/managers/NPCManager.java | 59 ++++----- .../de/cliffbreak/varo/uitls/BanUtils.java | 24 ++-- .../cliffbreak/varo/uitls/MessageUtils.java | 23 ++-- .../cliffbreak/varo/uitls/PacketReader.java | 28 ++-- .../de/cliffbreak/varo/uitls/PlayerCache.java | 18 +-- .../de/cliffbreak/varo/uitls/VaroUtils.java | 67 ++++++++++ .../de/cliffbreak/varo/uitls/WebUtils.java | 8 +- 19 files changed, 248 insertions(+), 217 deletions(-) delete mode 100644 varo/src/main/java/de/cliffbreak/varo/listeners/CreatureSpawnListener.java create mode 100644 varo/src/main/java/de/cliffbreak/varo/uitls/VaroUtils.java diff --git a/varo/src/main/java/de/cliffbreak/varo/Varo.java b/varo/src/main/java/de/cliffbreak/varo/Varo.java index 50f1098..34dcbdc 100644 --- a/varo/src/main/java/de/cliffbreak/varo/Varo.java +++ b/varo/src/main/java/de/cliffbreak/varo/Varo.java @@ -4,10 +4,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; -import org.bukkit.Difficulty; -import org.bukkit.GameRule; -import org.bukkit.NamespacedKey; -import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.configuration.file.YamlConfiguration; @@ -16,7 +12,6 @@ import de.cliffbreak.varo.commands.VaroCommand; import de.cliffbreak.varo.listeners.BannedActionListener; import de.cliffbreak.varo.listeners.BannedItemListener; import de.cliffbreak.varo.listeners.ChatListener; -import de.cliffbreak.varo.listeners.CreatureSpawnListener; import de.cliffbreak.varo.listeners.PlayerInteractNPCListener; import de.cliffbreak.varo.listeners.EntityRegainHealthListener; import de.cliffbreak.varo.listeners.PlayerClientOptionsChangeListener; @@ -26,97 +21,91 @@ import de.cliffbreak.varo.listeners.PlayerPreLoginListener; import de.cliffbreak.varo.managers.NPCManager; import de.cliffbreak.varo.uitls.BanUtils; import de.cliffbreak.varo.uitls.PlayerCache; +import de.cliffbreak.varo.uitls.VaroUtils; public class Varo extends JavaPlugin { - public File configurationFile = new File("plugins/CliffbreakVaro", "config.yml"); - public FileConfiguration config = YamlConfiguration.loadConfiguration(this.configurationFile); - public NPCManager npcManager; - public PlayerCache playerCache; - public BanUtils banUtils; + private File configurationFile; + private FileConfiguration config; + private NPCManager npcManager; + private PlayerCache playerCache; + private BanUtils banUtils; + private VaroUtils varoUtils; - public boolean canCreatePortal = false; + private boolean canCreatePortal = false; @Override public void onEnable() { - getLogger().info("CliffbreakVaro is starting..."); + this.getLogger().info("CliffbreakVaro is starting..."); + + this.configurationFile = new File("plugins/CliffbreakVaro", "config.yml"); + this.config = YamlConfiguration.loadConfiguration(this.configurationFile); this.npcManager = new NPCManager(this); this.playerCache = new PlayerCache(this); this.banUtils = new BanUtils(this); + this.varoUtils = new VaroUtils(this); // this.config.addDefault("Varo.Start", "TODO: StartDate"); this.config.addDefault("Varo.Debug", false); this.config.addDefault("Varo.Bans", new ArrayList()); this.config.options().copyDefaults(true); - this.saveConfiguration(); + this.saveConfig(); - getServer().getPluginManager().registerEvents(new PlayerPreLoginListener(this), this); - getServer().getPluginManager().registerEvents(new PlayerJoinQuitListener(this), this); - getServer().getPluginManager().registerEvents(new PlayerClientOptionsChangeListener(this), this); - getServer().getPluginManager().registerEvents(new ChatListener(), this); - getServer().getPluginManager().registerEvents(new EntityRegainHealthListener(), this); - getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this); - getServer().getPluginManager().registerEvents(new BannedItemListener(), this); - getServer().getPluginManager().registerEvents(new BannedActionListener(this), this); - getServer().getPluginManager().registerEvents(new CreatureSpawnListener(this), this); - getServer().getPluginManager().registerEvents(new PlayerInteractNPCListener(this), this); + this.getServer().getPluginManager().registerEvents(new PlayerPreLoginListener(this), this); + this.getServer().getPluginManager().registerEvents(new PlayerJoinQuitListener(this), this); + this.getServer().getPluginManager().registerEvents(new PlayerClientOptionsChangeListener(this), this); + this.getServer().getPluginManager().registerEvents(new ChatListener(), this); + this.getServer().getPluginManager().registerEvents(new EntityRegainHealthListener(), this); + this.getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this); + this.getServer().getPluginManager().registerEvents(new BannedItemListener(), this); + this.getServer().getPluginManager().registerEvents(new BannedActionListener(this), this); + this.getServer().getPluginManager().registerEvents(new PlayerInteractNPCListener(this), this); - getCommand("varo").setExecutor(new VaroCommand(this)); + this.getCommand("varo").setExecutor(new VaroCommand(this)); - for (World world : getServer().getWorlds()) { - world.setDifficulty(Difficulty.HARD); - world.setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false); - world.setGameRule(GameRule.COMMAND_BLOCK_OUTPUT, true); - world.setGameRule(GameRule.DISABLE_ELYTRA_MOVEMENT_CHECK, false); - world.setGameRule(GameRule.DISABLE_RAIDS, false); - world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, true); - world.setGameRule(GameRule.DO_ENTITY_DROPS, true); - world.setGameRule(GameRule.DO_FIRE_TICK, true); - world.setGameRule(GameRule.DO_INSOMNIA, false); - world.setGameRule(GameRule.DO_IMMEDIATE_RESPAWN, false); - world.setGameRule(GameRule.DO_LIMITED_CRAFTING, false); - world.setGameRule(GameRule.DO_MOB_LOOT, true); - world.setGameRule(GameRule.DO_MOB_SPAWNING, true); - world.setGameRule(GameRule.DO_PATROL_SPAWNING, true); - world.setGameRule(GameRule.DO_TILE_DROPS, true); - world.setGameRule(GameRule.DO_TRADER_SPAWNING, false); - world.setGameRule(GameRule.DO_WEATHER_CYCLE, true); - world.setGameRule(GameRule.DROWNING_DAMAGE, true); - world.setGameRule(GameRule.FALL_DAMAGE, true); - world.setGameRule(GameRule.FIRE_DAMAGE, true); - world.setGameRule(GameRule.KEEP_INVENTORY, false); - world.setGameRule(GameRule.LOG_ADMIN_COMMANDS, true); - world.setGameRule(GameRule.MOB_GRIEFING, true); - world.setGameRule(GameRule.NATURAL_REGENERATION, true); - world.setGameRule(GameRule.REDUCED_DEBUG_INFO, true); - world.setGameRule(GameRule.SEND_COMMAND_FEEDBACK, true); - world.setGameRule(GameRule.SHOW_DEATH_MESSAGES, true); - world.setGameRule(GameRule.SPECTATORS_GENERATE_CHUNKS, false); - - // DEBUG specific Settings - if (this.config.getBoolean("Varo.Debug")) { - world.setDifficulty(Difficulty.PEACEFUL); - world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false); - world.setGameRule(GameRule.DO_WEATHER_CYCLE, false); - } - } - getServer().removeRecipe(NamespacedKey.minecraft("fishing_rod")); + this.varoUtils.init(); } @Override public void onDisable() { - getLogger().info("Stopping CliffbreakVaro!"); + this.getLogger().info("Stopping CliffbreakVaro!"); this.playerCache.shutdown(); } - public void saveConfiguration() { + @Override + public FileConfiguration getConfig() { + return this.config; + } + + @Override + public void saveConfig() { try { - getLogger().info("Saving Config..."); + this.getLogger().info("Saving Config..."); this.config.save(this.configurationFile); - } catch (IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } + + public NPCManager getNPCManager() { + return npcManager; + } + + public PlayerCache getPlayerCache() { + return playerCache; + } + + public BanUtils getBanUtils() { + return this.banUtils; + } + + public boolean canCreatePortal() { + return this.canCreatePortal; + } + + public void setCanCreatePortal(final boolean canCreatePortal) { + this.canCreatePortal = canCreatePortal; + } } diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java index 1947666..8812b57 100644 --- a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java +++ b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java @@ -22,14 +22,15 @@ import de.cliffbreak.varo.uitls.WebUtils; public class VaroCommand implements CommandExecutor { - private Varo plugin; + private final Varo plugin; - public VaroCommand(Varo plugin) { + public VaroCommand(final Varo plugin) { this.plugin = plugin; } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { if (!sender.hasPermission("varo.admin")) { sender.sendMessage("§c§lFehler: §r§cNicht genügend Rechte für dieses Kommando."); return true; @@ -37,17 +38,17 @@ public class VaroCommand implements CommandExecutor { if (args.length == 2 && args[0].equals("unban")) { try { - String result = WebUtils.GET("https://api.mojang.com/users/profiles/minecraft/" + args[1]); + final String result = WebUtils.GET("https://api.mojang.com/users/profiles/minecraft/" + args[1]); if (result.isEmpty()) { sender.sendMessage("§c§lFehler: §r§cDer Spieler wurde nicht gefunden."); return true; } - JSONObject uuidObject = (JSONObject) JSONValue.parseWithException(result); - if (!plugin.banUtils.isBanned(uuidObject.get("id").toString())) { + final JSONObject uuidObject = (JSONObject) JSONValue.parseWithException(result); + if (!this.plugin.getBanUtils().isBanned(uuidObject.get("id").toString())) { sender.sendMessage("§c§lFehler: §r§cDer Spieler ist nicht gebannt."); return true; } - plugin.banUtils.removeBan(uuidObject.get("id").toString()); + this.plugin.getBanUtils().removeBan(uuidObject.get("id").toString()); sender.sendMessage("§a§lErfolg: §r§aDer Spieler ist nun nicht mehr gebannt."); } catch (IOException | ParseException e) { sender.sendMessage( @@ -57,10 +58,10 @@ public class VaroCommand implements CommandExecutor { } else if (args.length == 1 && args[0].equals("start")) { sender.sendMessage("§aStarting..."); - for (Player p : Bukkit.getServer().getOnlinePlayers()) { + for (final Player p : Bukkit.getServer().getOnlinePlayers()) { // p.getInventory().clear(); //TODO: uncomment after debuging p.closeInventory(Reason.CANT_USE); - for (PotionEffect potion : p.getActivePotionEffects()) + for (final PotionEffect potion : p.getActivePotionEffects()) p.removePotionEffect(potion.getType()); p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60 * 20, 1, false, false, false)); @@ -80,23 +81,23 @@ public class VaroCommand implements CommandExecutor { } else if (args.length == 2 && args[0].equals("portal")) { if (args[1].equals("enable")) { - this.plugin.canCreatePortal = true; + this.plugin.setCanCreatePortal(true); sender.sendMessage("§c§lWarnung: §r§cPortale können nun von JEDEM Spieler erstellt werden."); } else if (args[1].equals("disable")) { - this.plugin.canCreatePortal = false; + this.plugin.setCanCreatePortal(false); sender.sendMessage("§a§lErfolg: §r§aEs können nun keine Portale mehr erstellt werden.."); } else { sender.sendMessage("§c§lFehler: §r§cBitte überprüfe deine Eingabe."); } } else if (args.length == 1 && args[0].equals("test")) { if (sender instanceof Player) { - plugin.npcManager.createClone((Player) sender, false); + this.plugin.getNPCManager().createClone((Player) sender, false); } else { sender.sendMessage("§c§lFehler:§r§c Dieses Kommando kann nur durch einen Spieler ausgeführt werden."); } } else if (args.length == 1 && args[0].equals("testremove")) { if (sender instanceof Player) { - plugin.npcManager.removeClone(((Player) sender)); + this.plugin.getNPCManager().removeClone(((Player) sender)); } else { sender.sendMessage("§c§lFehler:§r§c Dieses Kommando kann nur durch einen Spieler ausgeführt werden."); } diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/BannedActionListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/BannedActionListener.java index 1b3f2d4..4326118 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/BannedActionListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/BannedActionListener.java @@ -19,7 +19,7 @@ public class BannedActionListener implements Listener { @EventHandler public void onPortalCreate(final PortalCreateEvent e) { - if (!this.plugin.canCreatePortal) { + if (!this.plugin.canCreatePortal()) { e.setCancelled(true); } } diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/BannedItemListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/BannedItemListener.java index 89c3633..fbbd430 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/BannedItemListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/BannedItemListener.java @@ -10,9 +10,9 @@ import org.bukkit.event.inventory.InventoryClickEvent; public class BannedItemListener implements Listener { @EventHandler - public void onEntityPickupItem(EntityPickupItemEvent e) { + public void onEntityPickupItem(final EntityPickupItemEvent e) { if (e.getEntity() instanceof Player) { - Material mat = e.getItem().getItemStack().getType(); + final Material mat = e.getItem().getItemStack().getType(); if (isForbiddenMaterial(mat)) { e.getEntity().sendMessage("§cVerbotenes Item wurde entfernt."); e.getItem().remove(); @@ -22,17 +22,17 @@ public class BannedItemListener implements Listener { } @EventHandler - public void onInventoryClick(InventoryClickEvent e) { + public void onInventoryClick(final InventoryClickEvent e) { if (e.getCurrentItem() == null) return; - Material mat = e.getCurrentItem().getType(); + final Material mat = e.getCurrentItem().getType(); if (isForbiddenMaterial(mat)) { e.getWhoClicked().sendMessage("§cVerbotenes Item kann nicht ins Inventar verschoben werden."); e.setCancelled(true); } } - private boolean isForbiddenMaterial(Material mat) { + private boolean isForbiddenMaterial(final Material mat) { return mat.equals(Material.ENCHANTED_GOLDEN_APPLE) || mat.equals(Material.FISHING_ROD) || mat.equals(Material.TOTEM_OF_UNDYING); } diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/ChatListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/ChatListener.java index a9a40ab..2057ea4 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/ChatListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/ChatListener.java @@ -10,7 +10,7 @@ import de.cliffbreak.varo.uitls.MessageUtils; public class ChatListener implements Listener { @EventHandler - public void onChat(AsyncPlayerChatEvent e) { + public void onChat(final AsyncPlayerChatEvent e) { e.setCancelled(true); Bukkit.broadcast(MessageUtils.getRichTextComponent(e.getPlayer().getName(), e.getMessage())); } diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/CreatureSpawnListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/CreatureSpawnListener.java deleted file mode 100644 index d4dbfa8..0000000 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/CreatureSpawnListener.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.cliffbreak.varo.listeners; - -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; - -import de.cliffbreak.varo.Varo; - -public class CreatureSpawnListener implements Listener { - - private Varo plugin; - - public CreatureSpawnListener(final Varo plugin) { - this.plugin = plugin; - } - - @EventHandler - public void onCreatureSpawn(CreatureSpawnEvent e) { - LivingEntity livingEntity = e.getEntity(); - if (livingEntity.getType().equals(EntityType.WANDERING_TRADER) - || livingEntity.getType().equals(EntityType.TRADER_LLAMA)) { - plugin.getLogger().info("Denied Wandering-Trader Spawn"); - e.setCancelled(true); - } - } -} \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/EntityRegainHealthListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/EntityRegainHealthListener.java index 8b7a540..874cdb7 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/EntityRegainHealthListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/EntityRegainHealthListener.java @@ -8,7 +8,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent; public class EntityRegainHealthListener implements Listener { @EventHandler - public void onEntityRegainHealth(EntityRegainHealthEvent e) { + public void onEntityRegainHealth(final EntityRegainHealthEvent e) { if (e.getEntity() instanceof Player) { if (e.isFastRegen()) { e.setAmount(0.13d); diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerClientOptionsChangeListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerClientOptionsChangeListener.java index af490b7..8a0d2ed 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerClientOptionsChangeListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerClientOptionsChangeListener.java @@ -10,16 +10,16 @@ import de.cliffbreak.varo.uitls.PlayerCache.PlayerCacheType; public class PlayerClientOptionsChangeListener implements Listener { - private Varo plugin; + private final Varo plugin; - public PlayerClientOptionsChangeListener(Varo plugin) { + public PlayerClientOptionsChangeListener(final Varo plugin) { this.plugin = plugin; } @EventHandler - public void onPlayerClientOptionsChange(PlayerClientOptionsChangeEvent e) { - String uuid = e.getPlayer().getUniqueId().toString().replace("-", ""); - plugin.playerCache.setPlayerCache(uuid, PlayerCacheType.SKINPARTS, e.getSkinParts().getRaw()); - plugin.playerCache.setPlayerCache(uuid, PlayerCacheType.MAINHAND, e.getMainHand().toString()); + public void onPlayerClientOptionsChange(final PlayerClientOptionsChangeEvent e) { + final String uuid = e.getPlayer().getUniqueId().toString().replace("-", ""); + this.plugin.getPlayerCache().setPlayerCache(uuid, PlayerCacheType.SKINPARTS, e.getSkinParts().getRaw()); + this.plugin.getPlayerCache().setPlayerCache(uuid, PlayerCacheType.MAINHAND, e.getMainHand().toString()); } } \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java index 34b7b94..b4708bd 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java @@ -1,10 +1,10 @@ package de.cliffbreak.varo.listeners; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.scheduler.BukkitRunnable; import de.cliffbreak.varo.Varo; @@ -18,16 +18,15 @@ public class PlayerDeathListener implements Listener { @EventHandler public void onPlayerDeath(final PlayerDeathEvent e) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + new BukkitRunnable() { @Override public void run() { e.getEntity().kickPlayer("§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden."); } - }, 20); - + }.runTaskLater(this.plugin, 20); e.getEntity().setHealth(20d); // Reset health to prevent death dialog after rejoin (if unbanned) e.getEntity().setGameMode(GameMode.SPECTATOR); - this.plugin.banUtils.addBann(e.getEntity().getUniqueId()); + this.plugin.getBanUtils().addBann(e.getEntity().getUniqueId()); } } \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerInteractNPCListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerInteractNPCListener.java index 8cef25b..e4d0431 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerInteractNPCListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerInteractNPCListener.java @@ -9,17 +9,16 @@ import de.cliffbreak.varo.events.PlayerInteractNPCEvent.Type; public class PlayerInteractNPCListener implements Listener { - private Varo plugin; + private final Varo plugin; - public PlayerInteractNPCListener(Varo plugin) { + public PlayerInteractNPCListener(final Varo plugin) { this.plugin = plugin; } @EventHandler - public void onEntityDamageByEntity(PlayerInteractNPCEvent e) { - // plugin.getLogger().info(e.getType().toString() + " : " + e.getId() + " : " + e.getDamage()); + public void onEntityDamageByEntity(final PlayerInteractNPCEvent e) { if (e.getType().equals(Type.ATTACK)) { - plugin.npcManager.addDamage(e.getId(), e.getDamage(), e.getIsCritical()); + this.plugin.getNPCManager().addDamage(e.getId(), e.getDamage(), e.getIsCritical()); } } diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java index 2ec9875..89c7e4c 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java @@ -27,7 +27,7 @@ public class PlayerJoinQuitListener implements Listener { @EventHandler public void onPlayerQuit(final PlayerQuitEvent e) { e.setQuitMessage(null); - plugin.npcManager.createClone(e.getPlayer(), true); + this.plugin.getNPCManager().createClone(e.getPlayer(), true); Bukkit.broadcast( MessageUtils.getRichTextComponent(e.getPlayer().getName(), "§f hat den Server verlassen.", true)); } @@ -35,17 +35,17 @@ public class PlayerJoinQuitListener implements Listener { @EventHandler public void onPlayerJoin(final PlayerJoinEvent e) { e.setJoinMessage(null); - plugin.npcManager.removeClone(e.getPlayer()); - plugin.npcManager.syncClones(e.getPlayer()); + this.plugin.getNPCManager().removeClone(e.getPlayer()); + this.plugin.getNPCManager().syncClones(e.getPlayer()); // Inject PacketReader - PacketReader packetReader = new PacketReader(plugin, e.getPlayer()); + final PacketReader packetReader = new PacketReader(this.plugin, e.getPlayer()); packetReader.inject(); Bukkit.broadcast( MessageUtils.getRichTextComponent(e.getPlayer().getName(), "§f hat den Server betreten.", true)); - if (plugin.config.getBoolean("Varo.Debug")) { + if (this.plugin.getConfig().getBoolean("Varo.Debug")) { e.getPlayer().sendMessage("\n§7§l#### §9Cliffbreak.de - §lVaro §r§9Changelog §7§l####\n \n" + " §cWarning: §r§c Plugin is running in DEBUG mode!\n "); @@ -88,7 +88,7 @@ public class PlayerJoinQuitListener implements Listener { } e.getPlayer().sendMessage(changes.pop()); } - }.runTaskTimer(plugin, 20, 20); + }.runTaskTimer(this.plugin, 20, 20); } } } @@ -98,7 +98,7 @@ public class PlayerJoinQuitListener implements Listener { if (event instanceof PaperServerListPingEvent) { handlePaperServerListPing((PaperServerListPingEvent) event); } else { - plugin.getLogger().info("Error: Plugin is not running on a PaperServer"); + this.plugin.getLogger().info("Error: Plugin is not running on a PaperServer"); } } diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerPreLoginListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerPreLoginListener.java index fed391b..b6caca8 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerPreLoginListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerPreLoginListener.java @@ -17,7 +17,7 @@ public class PlayerPreLoginListener implements Listener { @EventHandler public void onPlayerPreLogin(final PlayerLoginEvent e) { - if (plugin.banUtils.isBanned(e.getPlayer().getUniqueId())) { + if (this.plugin.getBanUtils().isBanned(e.getPlayer().getUniqueId())) { e.disallow(Result.KICK_BANNED, "§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden."); } } diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java index ded1207..61a6ee2 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java @@ -52,7 +52,7 @@ public class NPCManager { private final Varo plugin; private final ArrayList npcs = new ArrayList(); private final HashMap inventories = new HashMap(); - private Scoreboard scoreboard; + private final Scoreboard scoreboard; private Team afkTeam; public NPCManager(final Varo plugin) { @@ -83,7 +83,7 @@ public class NPCManager { gameProfile.getProperties().put("textures", new Property("textures", properties.get("value").toString(), properties.get("signature").toString())); } catch (IOException | ParseException e) { - plugin.getLogger().info(e.getMessage()); + this.plugin.getLogger().info(e.getMessage()); } final PlayerInteractManager playerInteractManager = new PlayerInteractManager(nmsWorld); final EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, playerInteractManager); @@ -98,27 +98,28 @@ public class NPCManager { npcs.add(npc); - for (Player connectionPlayer : Bukkit.getOnlinePlayers()) { + for (final Player connectionPlayer : Bukkit.getOnlinePlayers()) { final PlayerConnection connection = ((CraftPlayer) connectionPlayer).getHandle().playerConnection; new BukkitRunnable() { @Override public void run() { connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc)); } - }.runTaskLater(plugin, 20); + }.runTaskLater(this.plugin, 20); connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc)); connection.sendPacket( new PacketPlayOutEntityHeadRotation(npc, (byte) ((location.getYaw() * 256.0F) / 360.0F))); npc.getDataWatcher().set(new DataWatcherObject<>(16, DataWatcherRegistry.a), - (byte) plugin.playerCache.getSkinParts(player.getUniqueId().toString().replace("-", ""))); + (byte) this.plugin.getPlayerCache().getSkinParts(player.getUniqueId().toString().replace("-", ""))); npc.getDataWatcher().set(new DataWatcherObject<>(17, DataWatcherRegistry.a), - plugin.playerCache.getMainHandAsByte(player.getUniqueId().toString().replace("-", ""))); + this.plugin.getPlayerCache().getMainHandAsByte(player.getUniqueId().toString().replace("-", ""))); connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true)); sendEquipmentPackets(connection, npc.getId(), player.getInventory()); } } - private void sendEquipmentPackets(PlayerConnection connection, int id, PlayerInventory inventory) { + private void sendEquipmentPackets(final PlayerConnection connection, final int id, + final PlayerInventory inventory) { connection.sendPacket(new PacketPlayOutEntityEquipment(id, EnumItemSlot.MAINHAND, CraftItemStack.asNMSCopy(inventory.getItemInMainHand()))); connection.sendPacket(new PacketPlayOutEntityEquipment(id, EnumItemSlot.OFFHAND, @@ -133,38 +134,38 @@ public class NPCManager { CraftItemStack.asNMSCopy(inventory.getHelmet()))); } - public void syncClones(Player player) { - for (EntityPlayer npc : this.npcs) { + public void syncClones(final Player player) { + for (final EntityPlayer npc : this.npcs) { final PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc)); connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc)); connection.sendPacket(new PacketPlayOutEntityHeadRotation(npc, (byte) ((npc.yaw * 256.0F) / 360.0F))); npc.getDataWatcher().set(new DataWatcherObject<>(16, DataWatcherRegistry.a), - (byte) plugin.playerCache.getSkinParts(player.getUniqueId().toString().replace("-", ""))); + (byte) this.plugin.getPlayerCache().getSkinParts(player.getUniqueId().toString().replace("-", ""))); npc.getDataWatcher().set(new DataWatcherObject<>(17, DataWatcherRegistry.a), - plugin.playerCache.getMainHandAsByte(player.getUniqueId().toString().replace("-", ""))); + this.plugin.getPlayerCache().getMainHandAsByte(player.getUniqueId().toString().replace("-", ""))); connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true)); sendEquipmentPackets(connection, npc.getId(), this.inventories.get(npc.getUniqueID())); } } - public boolean isNPC(int id) { - for (EntityPlayer npc : this.npcs) { + public boolean isNPC(final int id) { + for (final EntityPlayer npc : this.npcs) { if (npc.getId() == id) return true; } return false; } - public void addDamage(int id, double damage, boolean isCritical) { - for (EntityPlayer npc : this.npcs) { + public void addDamage(final int id, final double damage, final boolean isCritical) { + for (final EntityPlayer npc : this.npcs) { if (npc.getId() == id) { npc.setHealth((float) (npc.getHealth() - damage)); - World world = npc.getWorld().getWorld(); - Location loc = new Location(world, npc.locX(), npc.locY(), npc.locZ()); + final World world = npc.getWorld().getWorld(); + final Location loc = new Location(world, npc.locX(), npc.locY(), npc.locZ()); if (npc.getHealth() > 0.0F) { - for (Player connectionPlayer : Bukkit.getOnlinePlayers()) { + for (final Player connectionPlayer : Bukkit.getOnlinePlayers()) { final PlayerConnection connection = ((CraftPlayer) connectionPlayer) .getHandle().playerConnection; connection.sendPacket(new PacketPlayOutEntityStatus(npc, (byte) 2)); // Send HURT (2) Animation @@ -175,7 +176,7 @@ public class NPCManager { world.playSound(loc, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0F, 1.0F); } else { // Send Death Animation Packet - for (Player connectionPlayer : Bukkit.getOnlinePlayers()) { + for (final Player connectionPlayer : Bukkit.getOnlinePlayers()) { final PlayerConnection connection = ((CraftPlayer) connectionPlayer) .getHandle().playerConnection; connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true)); @@ -187,15 +188,15 @@ public class NPCManager { new BukkitRunnable() { @Override public void run() { - for (ItemStack item : inventories.get(npc.getUniqueID())) { + for (final ItemStack item : inventories.get(npc.getUniqueID())) { if (item != null) world.dropItem(loc, item); } } - }.runTask(plugin); // Run Task in sync to be thread safe + }.runTask(this.plugin); // Run Task in sync to be thread safe - this.plugin.banUtils.addBann(npc.getUniqueID()); + this.plugin.getBanUtils().addBann(npc.getUniqueID()); Bukkit.broadcastMessage("TODO: Player(" + "??" + ") killed AFK Player (" + npc.getName() + ")"); new BukkitRunnable() { @@ -203,7 +204,7 @@ public class NPCManager { public void run() { removeClone(npc.getUniqueID()); } - }.runTaskLater(plugin, 20); + }.runTaskLater(this.plugin, 20); } } @@ -211,15 +212,15 @@ public class NPCManager { } // FIXME: Only for debug reasons -- Remove - public void removeClone(Player player) { + public void removeClone(final Player player) { this.afkTeam.removeEntry(player.getName()); for (int i = 0; i < this.npcs.size(); i++) { - EntityPlayer npc = this.npcs.get(i); + final EntityPlayer npc = this.npcs.get(i); if (npc.getUniqueID().equals(player.getUniqueId())) { final WorldServer nmsWorld = ((CraftWorld) player.getWorld()).getHandle(); nmsWorld.removeEntity(npc); - for (Player connectionPlayer : Bukkit.getOnlinePlayers()) { + for (final Player connectionPlayer : Bukkit.getOnlinePlayers()) { final PlayerConnection connection = ((CraftPlayer) connectionPlayer).getHandle().playerConnection; connection.sendPacket(new PacketPlayOutEntityDestroy(npc.getId())); } @@ -228,13 +229,13 @@ public class NPCManager { } } - public void removeClone(UUID uuid) { + public void removeClone(final UUID uuid) { for (int i = 0; i < this.npcs.size(); i++) { - EntityPlayer npc = this.npcs.get(i); + final EntityPlayer npc = this.npcs.get(i); if (npc.getUniqueID().equals(uuid)) { final WorldServer nmsWorld = npc.getWorldServer(); - for (Player connectionPlayer : Bukkit.getOnlinePlayers()) { + for (final Player connectionPlayer : Bukkit.getOnlinePlayers()) { final PlayerConnection connection = ((CraftPlayer) connectionPlayer).getHandle().playerConnection; connection.sendPacket(new PacketPlayOutEntityDestroy(npc.getId())); connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, npc)); diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java b/varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java index d193072..b301302 100644 --- a/varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java @@ -9,34 +9,34 @@ public class BanUtils { private final Varo plugin; - public BanUtils(Varo plugin) { + public BanUtils(final Varo plugin) { this.plugin = plugin; } - public boolean isBanned(UUID uuid) { + public boolean isBanned(final UUID uuid) { return isBanned(uuid.toString().replace("-", "")); } - public boolean isBanned(String compressedUuid) { + public boolean isBanned(final String compressedUuid) { @SuppressWarnings("unchecked") - final ArrayList bans = (ArrayList) this.plugin.config.get("Varo.Bans"); + final ArrayList bans = (ArrayList) this.plugin.getConfig().get("Varo.Bans"); return bans.contains(compressedUuid); } - public void addBann(UUID uuid) { + public void addBann(final UUID uuid) { @SuppressWarnings("unchecked") - final ArrayList bans = (ArrayList) this.plugin.config.get("Varo.Bans"); + final ArrayList bans = (ArrayList) this.plugin.getConfig().get("Varo.Bans"); bans.add(uuid.toString().replace("-", "")); - this.plugin.config.set("Varo.Bans", bans); - this.plugin.saveConfiguration(); + this.plugin.getConfig().set("Varo.Bans", bans); + this.plugin.saveConfig(); } - public void removeBan(String compressedUuid) { + public void removeBan(final String compressedUuid) { @SuppressWarnings("unchecked") - final ArrayList bans = (ArrayList) this.plugin.config.get("Varo.Bans"); + final ArrayList bans = (ArrayList) this.plugin.getConfig().get("Varo.Bans"); bans.remove(compressedUuid); - this.plugin.config.set("Varo.Bans", bans); - this.plugin.saveConfiguration(); + this.plugin.getConfig().set("Varo.Bans", bans); + this.plugin.saveConfig(); } } \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/MessageUtils.java b/varo/src/main/java/de/cliffbreak/varo/uitls/MessageUtils.java index 2962d84..ad5aaf4 100644 --- a/varo/src/main/java/de/cliffbreak/varo/uitls/MessageUtils.java +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/MessageUtils.java @@ -9,7 +9,7 @@ import net.md_5.bungee.api.chat.TextComponent; public class MessageUtils { - public static String getTimestampedMessage(String message) { + public static String getTimestampedMessage(final String message) { return " §8" + getTimestamp() + " §7| " + message; } @@ -23,7 +23,7 @@ public class MessageUtils { * the message to send * @return TextComponent */ - public static TextComponent getRichTextComponent(String player, String message) { + public static TextComponent getRichTextComponent(final String player, final String message) { return getRichTextComponent(player, message, false, true); } @@ -38,7 +38,8 @@ public class MessageUtils { * is this a service message (f.e. PlayerJoinEvent) * @return TextComponent */ - public static TextComponent getRichTextComponent(String player, String message, boolean isServiceMessage) { + public static TextComponent getRichTextComponent(final String player, final String message, + final boolean isServiceMessage) { return getRichTextComponent(player, message, isServiceMessage, true); } @@ -55,12 +56,12 @@ public class MessageUtils { * should a timestamp be returned? * @return TextComponent */ - public static TextComponent getRichTextComponent(String player, String message, boolean isServiceMessage, - boolean useTimestamp) { - TextComponent mainComponent = new TextComponent(" "); - TextComponent timeComponent = new TextComponent("§8" + getTimestamp() + " §7| "); - TextComponent playerComponent = new TextComponent("§b" + player); - TextComponent messageComponent = new TextComponent(" §7>> §r§f" + message); + public static TextComponent getRichTextComponent(final String player, final String message, + final boolean isServiceMessage, final boolean useTimestamp) { + final TextComponent mainComponent = new TextComponent(" "); + final TextComponent timeComponent = new TextComponent("§8" + getTimestamp() + " §7| "); + final TextComponent playerComponent = new TextComponent("§b" + player); + final TextComponent messageComponent = new TextComponent(" §7>> §r§f" + message); timeComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7" + getTimestampSeconds()).create())); playerComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, @@ -78,13 +79,13 @@ public class MessageUtils { } private static String getTimestamp() { - Calendar calendar = Calendar.getInstance(); + final Calendar calendar = Calendar.getInstance(); return String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY)) + ":" + String.format("%02d", calendar.get(Calendar.MINUTE)); } private static String getTimestampSeconds() { - Calendar calendar = Calendar.getInstance(); + final Calendar calendar = Calendar.getInstance(); return String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY)) + ":" + String.format("%02d", calendar.get(Calendar.MINUTE)) + ":" + String.format("%02d", calendar.get(Calendar.SECOND)); diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/PacketReader.java b/varo/src/main/java/de/cliffbreak/varo/uitls/PacketReader.java index bd2570c..d0073db 100644 --- a/varo/src/main/java/de/cliffbreak/varo/uitls/PacketReader.java +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/PacketReader.java @@ -26,8 +26,8 @@ import net.minecraft.server.v1_15_R1.Packet; public class PacketReader { - private Varo plugin; - private Player player; + private final Varo plugin; + private final Player player; private Channel channel; public PacketReader(final Varo plugin, final Player player) { @@ -58,30 +58,30 @@ public class PacketReader { public void readPacket(final Packet packet) { if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) { - int id = (int) getValue(packet, "a"); - if (!plugin.npcManager.isNPC(id)) { + final int id = (int) getValue(packet, "a"); + if (!this.plugin.getNPCManager().isNPC(id)) { return; } try { - Type type = Type.valueOf(getValue(packet, "action").toString()); - PlayerInteractNPCEvent event = new PlayerInteractNPCEvent(type, id, calculateDamage(this.player), + final Type type = Type.valueOf(getValue(packet, "action").toString()); + final PlayerInteractNPCEvent event = new PlayerInteractNPCEvent(type, id, calculateDamage(this.player), isCriticalHit(this.player)); Bukkit.getServer().getPluginManager().callEvent(event); - } catch (Exception e) { + } catch (final Exception e) { // noop() } } } - private double calculateDamage(Player player) { + private double calculateDamage(final Player player) { double damage = 1.0; // Default 1.0 Damage (by hand) - ItemStack nmsItemStack = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - Collection attributes = nmsItemStack.getItem().a(EnumItemSlot.MAINHAND) + final ItemStack nmsItemStack = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); + final Collection attributes = nmsItemStack.getItem().a(EnumItemSlot.MAINHAND) .get(GenericAttributes.ATTACK_DAMAGE.getName()); - for (AttributeModifier am : attributes) { + for (final AttributeModifier am : attributes) { damage += am.getAmount(); } @@ -91,9 +91,9 @@ public class PacketReader { damage = damage * player.getAttackCooldown(); - Map enchantments = player.getInventory().getItemInMainHand().getEnchantments(); + final Map enchantments = player.getInventory().getItemInMainHand().getEnchantments(); - for (Map.Entry enchantment : enchantments.entrySet()) { + for (final Map.Entry enchantment : enchantments.entrySet()) { // TODO: Add more enchantments? if (enchantment.getKey().equals(Enchantment.DAMAGE_ALL)) damage += 0.5 * (enchantment.getValue() + 1); @@ -101,7 +101,7 @@ public class PacketReader { return damage; } - private boolean isCriticalHit(Player player) { + private boolean isCriticalHit(final Player player) { return player.getFallDistance() > 0.0F && !player.isOnGround() && !player.getLocation().getBlock().isLiquid() && player.getPotionEffect(PotionEffectType.BLINDNESS) == null && player.getVehicle() == null && !player.isSprinting() && player.getAttackCooldown() > 0.848F; diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/PlayerCache.java b/varo/src/main/java/de/cliffbreak/varo/uitls/PlayerCache.java index 983a3e6..15bc385 100644 --- a/varo/src/main/java/de/cliffbreak/varo/uitls/PlayerCache.java +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/PlayerCache.java @@ -12,16 +12,18 @@ import de.cliffbreak.varo.Varo; public class PlayerCache { - private Varo plugin; - private File playerCacheFile = new File("plugins/CliffbreakVaro", "playercache.yml"); - private FileConfiguration playerCache = YamlConfiguration.loadConfiguration(this.playerCacheFile); + private final Varo plugin; + private final File playerCacheFile; + private final FileConfiguration playerCache; private boolean wasSaved = false; - public PlayerCache(Varo plugin) { + public PlayerCache(final Varo plugin) { + this.playerCacheFile = new File("plugins/CliffbreakVaro", "playercache.yml"); + this.playerCache = YamlConfiguration.loadConfiguration(this.playerCacheFile); this.plugin = plugin; } - public void setPlayerCache(final String uuid, PlayerCacheType type, Object value) { + public void setPlayerCache(final String uuid, final PlayerCacheType type, final Object value) { this.playerCache.set("Players." + uuid + "." + type.toString(), value); savePlayerCache(); } @@ -44,7 +46,7 @@ public class PlayerCache { public void shutdown() { try { - plugin.getLogger().info("Saving PlayerCache..."); + this.plugin.getLogger().info("Saving PlayerCache..."); this.playerCache.save(this.playerCacheFile); } catch (final IOException e) { e.printStackTrace(); @@ -54,7 +56,7 @@ public class PlayerCache { private void savePlayerCache() { if (!this.wasSaved) try { - plugin.getLogger().info("Saving PlayerCache..."); + this.plugin.getLogger().info("Saving PlayerCache..."); this.playerCache.save(this.playerCacheFile); this.wasSaved = true; new BukkitRunnable() { @@ -63,7 +65,7 @@ public class PlayerCache { public void run() { wasSaved = false; } - }.runTaskLater(plugin, 20); // Only save once every second to prevent disklock + }.runTaskLater(this.plugin, 20); // Only save once every second to prevent disklock } catch (final IOException e) { e.printStackTrace(); } diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/VaroUtils.java b/varo/src/main/java/de/cliffbreak/varo/uitls/VaroUtils.java new file mode 100644 index 0000000..594e852 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/VaroUtils.java @@ -0,0 +1,67 @@ +package de.cliffbreak.varo.uitls; + +import org.bukkit.Difficulty; +import org.bukkit.GameRule; +import org.bukkit.NamespacedKey; +import org.bukkit.World; + +import de.cliffbreak.varo.Varo; + +public class VaroUtils { + + private final Varo plugin; + + public VaroUtils(final Varo plugin) { + this.plugin = plugin; + } + + public void init() { + this.initGameRules(); + this.initRecipes(); + } + + private void initGameRules() { + for (final World world : this.plugin.getServer().getWorlds()) { + world.setDifficulty(Difficulty.HARD); + world.setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false); + world.setGameRule(GameRule.COMMAND_BLOCK_OUTPUT, true); + world.setGameRule(GameRule.DISABLE_ELYTRA_MOVEMENT_CHECK, false); + world.setGameRule(GameRule.DISABLE_RAIDS, false); + world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, true); + world.setGameRule(GameRule.DO_ENTITY_DROPS, true); + world.setGameRule(GameRule.DO_FIRE_TICK, true); + world.setGameRule(GameRule.DO_INSOMNIA, false); + world.setGameRule(GameRule.DO_IMMEDIATE_RESPAWN, false); + world.setGameRule(GameRule.DO_LIMITED_CRAFTING, false); + world.setGameRule(GameRule.DO_MOB_LOOT, true); + world.setGameRule(GameRule.DO_MOB_SPAWNING, true); + world.setGameRule(GameRule.DO_PATROL_SPAWNING, true); + world.setGameRule(GameRule.DO_TILE_DROPS, true); + world.setGameRule(GameRule.DO_TRADER_SPAWNING, false); + world.setGameRule(GameRule.DO_WEATHER_CYCLE, true); + world.setGameRule(GameRule.DROWNING_DAMAGE, true); + world.setGameRule(GameRule.FALL_DAMAGE, true); + world.setGameRule(GameRule.FIRE_DAMAGE, true); + world.setGameRule(GameRule.KEEP_INVENTORY, false); + world.setGameRule(GameRule.LOG_ADMIN_COMMANDS, true); + world.setGameRule(GameRule.MOB_GRIEFING, true); + world.setGameRule(GameRule.NATURAL_REGENERATION, true); + world.setGameRule(GameRule.REDUCED_DEBUG_INFO, true); + world.setGameRule(GameRule.SEND_COMMAND_FEEDBACK, true); + world.setGameRule(GameRule.SHOW_DEATH_MESSAGES, true); + world.setGameRule(GameRule.SPECTATORS_GENERATE_CHUNKS, false); + + // DEBUG specific Settings + if (this.plugin.getConfig().getBoolean("Varo.Debug")) { + world.setDifficulty(Difficulty.PEACEFUL); + world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false); + world.setGameRule(GameRule.DO_WEATHER_CYCLE, false); + } + } + } + + private void initRecipes() { + this.plugin.getServer().removeRecipe(NamespacedKey.minecraft("fishing_rod")); + } + +} \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/WebUtils.java b/varo/src/main/java/de/cliffbreak/varo/uitls/WebUtils.java index e9e0050..0ad1e60 100644 --- a/varo/src/main/java/de/cliffbreak/varo/uitls/WebUtils.java +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/WebUtils.java @@ -9,12 +9,12 @@ import java.net.URL; public class WebUtils { - public static String GET(String url) throws MalformedURLException, IOException { - HttpURLConnection connection = ((HttpURLConnection) (new URL(url)).openConnection()); + public static String GET(final String url) throws MalformedURLException, IOException { + final HttpURLConnection connection = ((HttpURLConnection) (new URL(url)).openConnection()); connection.setRequestMethod("GET"); - BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; - StringBuffer content = new StringBuffer(); + final StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); }