diff --git a/src/main/java/eu/endermite/togglepvp/TogglePvP.java b/src/main/java/eu/endermite/togglepvp/TogglePvp.java similarity index 86% rename from src/main/java/eu/endermite/togglepvp/TogglePvP.java rename to src/main/java/eu/endermite/togglepvp/TogglePvp.java index 9de2faf..f4f3ea8 100644 --- a/src/main/java/eu/endermite/togglepvp/TogglePvP.java +++ b/src/main/java/eu/endermite/togglepvp/TogglePvp.java @@ -2,11 +2,6 @@ import eu.endermite.togglepvp.commands.MainCommand; import eu.endermite.togglepvp.config.ConfigCache; -import eu.endermite.togglepvp.listeners.player.*; -import eu.endermite.togglepvp.listeners.player.WolfAttackPlayerListener; -import eu.endermite.togglepvp.listeners.wolf.WolfTargettingPlayerListener; -import eu.endermite.togglepvp.listeners.unspecific.*; -import eu.endermite.togglepvp.listeners.wolf.*; import eu.endermite.togglepvp.players.PlayerManager; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.Listener; @@ -15,16 +10,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; import org.reflections.Reflections; -import org.reflections.scanners.TypeAnnotationsScanner; - import java.io.File; import java.lang.reflect.InvocationTargetException; import java.util.Objects; import java.util.Set; -public final class TogglePvP extends JavaPlugin { +public final class TogglePvp extends JavaPlugin { - @Getter private static TogglePvP plugin; + @Getter private static TogglePvp plugin; private ConfigCache configCache; private PlayerManager playerManager; private DatabaseSQLite sqLite; diff --git a/src/main/java/eu/endermite/togglepvp/TogglePvpAPI.java b/src/main/java/eu/endermite/togglepvp/TogglePvpAPI.java new file mode 100644 index 0000000..d793217 --- /dev/null +++ b/src/main/java/eu/endermite/togglepvp/TogglePvpAPI.java @@ -0,0 +1,27 @@ +package eu.endermite.togglepvp; + +import eu.endermite.togglepvp.players.SmartCache; +import java.util.UUID; + +public class TogglePvpAPI { + + /** + * Sets player PvP state. This will always save to database. + * @param uuid uuid of player to set + * @param newState State to set + */ + public static void setPvpEnabled(UUID uuid, boolean newState) { + SmartCache.setPlayerPvpState(uuid, newState); + } + + /** + * Gets player's PvP state. If player is not cached this will query the database. + * @param uuid uuid of player to get data from. + * @return true if enabled, false if disabled + */ + public static boolean getPvpEnabled(UUID uuid) { + return SmartCache.getPlayerData(uuid).isPvpEnabled(); + } + + +} diff --git a/src/main/java/eu/endermite/togglepvp/commands/HelpCommand.java b/src/main/java/eu/endermite/togglepvp/commands/HelpCommand.java index 9cd3f7c..a85d82f 100644 --- a/src/main/java/eu/endermite/togglepvp/commands/HelpCommand.java +++ b/src/main/java/eu/endermite/togglepvp/commands/HelpCommand.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.commands; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.util.PluginMessages; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class HelpCommand { public static void help(CommandSender sender, String[] args) { - Bukkit.getScheduler().runTaskAsynchronously(TogglePvP.getPlugin(), () -> { + Bukkit.getScheduler().runTaskAsynchronously(TogglePvp.getPlugin(), () -> { List helpPage = new ArrayList<>(); diff --git a/src/main/java/eu/endermite/togglepvp/commands/MainCommand.java b/src/main/java/eu/endermite/togglepvp/commands/MainCommand.java index 01632e6..7245396 100644 --- a/src/main/java/eu/endermite/togglepvp/commands/MainCommand.java +++ b/src/main/java/eu/endermite/togglepvp/commands/MainCommand.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.commands; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.util.PluginMessages; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -33,14 +33,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St ReloadCommand.reload(sender); break; default: - sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getNo_such_command())); + sender.sendMessage(PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getNo_such_command())); break; } } else { HelpCommand.help(sender, args); } } else { - sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getNo_permission())); + sender.sendMessage(PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getNo_permission())); } return true; } diff --git a/src/main/java/eu/endermite/togglepvp/commands/PvpToggleCommand.java b/src/main/java/eu/endermite/togglepvp/commands/PvpToggleCommand.java index 220c80d..c72463b 100644 --- a/src/main/java/eu/endermite/togglepvp/commands/PvpToggleCommand.java +++ b/src/main/java/eu/endermite/togglepvp/commands/PvpToggleCommand.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.commands; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.util.CombatTimer; import eu.endermite.togglepvp.util.PluginMessages; import net.md_5.bungee.api.ChatMessageType; @@ -14,10 +14,10 @@ public class PvpToggleCommand { public static void toggle(CommandSender sender, String[] args) { - Bukkit.getScheduler().runTaskAsynchronously(TogglePvP.getPlugin(), () -> { + Bukkit.getScheduler().runTaskAsynchronously(TogglePvp.getPlugin(), () -> { if (!sender.hasPermission("togglepvp.command.toggle")) { - String message = TogglePvP.getPlugin().getConfigCache().getNo_permission(); + String message = TogglePvp.getPlugin().getConfigCache().getNo_permission(); BaseComponent[] component = TextComponent.fromLegacyText(message); sender.spigot().sendMessage(component); return; @@ -28,17 +28,17 @@ public static void toggle(CommandSender sender, String[] args) { Player player = (Player) sender; if (CombatTimer.isInCombat(player.getUniqueId())) { - sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getCant_do_that_during_combat())); + sender.sendMessage(PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getCant_do_that_during_combat())); return; } - boolean currentState = TogglePvP.getPlugin().getPlayerManager().togglePlayerPvpState(player.getUniqueId()); + boolean currentState = TogglePvp.getPlugin().getPlayerManager().togglePlayerPvpState(player.getUniqueId()); String message = ""; if (currentState) { - message = PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getPvp_enabled()); + message = PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getPvp_enabled()); } else { - message = PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getPvp_disabled()); + message = PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getPvp_disabled()); } BaseComponent[] component = TextComponent.fromLegacyText(message); player.spigot().sendMessage(ChatMessageType.CHAT, component); @@ -47,7 +47,7 @@ public static void toggle(CommandSender sender, String[] args) { } } else if (args.length == 2) { if (!sender.hasPermission("togglepvp.command.toggle.others")) { - String message = TogglePvP.getPlugin().getConfigCache().getNo_permission(); + String message = TogglePvp.getPlugin().getConfigCache().getNo_permission(); BaseComponent[] component = TextComponent.fromLegacyText(message); sender.spigot().sendMessage(component); return; @@ -56,18 +56,18 @@ public static void toggle(CommandSender sender, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (CombatTimer.isInCombat(player.getUniqueId())) { - sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getCant_do_that_during_combat())); + sender.sendMessage(PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getCant_do_that_during_combat())); return; } } try { Player player = Bukkit.getPlayer(args[1]); - boolean currentState = TogglePvP.getPlugin().getPlayerManager().togglePlayerPvpState(player.getUniqueId()); + boolean currentState = TogglePvp.getPlugin().getPlayerManager().togglePlayerPvpState(player.getUniqueId()); String message; if (currentState) { - message = TogglePvP.getPlugin().getConfigCache().getPvp_enabled_other(); + message = TogglePvp.getPlugin().getConfigCache().getPvp_enabled_other(); } else { - message = TogglePvP.getPlugin().getConfigCache().getPvp_disabled_other(); + message = TogglePvp.getPlugin().getConfigCache().getPvp_disabled_other(); } sender.sendMessage(PluginMessages.parsePlayerName(player, message)); @@ -86,7 +86,7 @@ public static void toggle(CommandSender sender, String[] args) { public static void enable(CommandSender sender, String[] args) { if (!sender.hasPermission("togglepvp.command.toggle")) { - String message = TogglePvP.getPlugin().getConfigCache().getNo_permission(); + String message = TogglePvp.getPlugin().getConfigCache().getNo_permission(); BaseComponent[] component = TextComponent.fromLegacyText(message); sender.spigot().sendMessage(component); return; @@ -95,11 +95,11 @@ public static void enable(CommandSender sender, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (CombatTimer.isInCombat(player.getUniqueId())) { - sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getCant_do_that_during_combat())); + sender.sendMessage(PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getCant_do_that_during_combat())); return; } - TogglePvP.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true); - String message = PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getPvp_enabled()); + TogglePvp.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true); + String message = PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getPvp_enabled()); BaseComponent[] component = TextComponent.fromLegacyText(message); player.spigot().sendMessage(ChatMessageType.CHAT, component); } else { @@ -107,7 +107,7 @@ public static void enable(CommandSender sender, String[] args) { } } else if (args.length == 2) { if (!sender.hasPermission("togglepvp.command.toggle.others")) { - String message = TogglePvP.getPlugin().getConfigCache().getNo_permission(); + String message = TogglePvp.getPlugin().getConfigCache().getNo_permission(); BaseComponent[] component = TextComponent.fromLegacyText(message); sender.spigot().sendMessage(component); return; @@ -115,15 +115,15 @@ public static void enable(CommandSender sender, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (CombatTimer.isInCombat(player.getUniqueId())) { - sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getCant_do_that_during_combat())); + sender.sendMessage(PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getCant_do_that_during_combat())); return; } } try { Player player = Bukkit.getPlayer(args[1]); - String message = TogglePvP.getPlugin().getConfigCache().getPvp_enabled_other(); + String message = TogglePvp.getPlugin().getConfigCache().getPvp_enabled_other(); sender.sendMessage(PluginMessages.parsePlayerName(player, message)); - TogglePvP.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true); + TogglePvp.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true); } catch (NullPointerException e) { sender.sendMessage(PluginMessages.parseMessage("&cPlayer offline.")); } @@ -138,7 +138,7 @@ public static void enable(CommandSender sender, String[] args) { public static void disable(CommandSender sender, String[] args) { if (!sender.hasPermission("togglepvp.command.toggle")) { - String message = TogglePvP.getPlugin().getConfigCache().getNo_permission(); + String message = TogglePvp.getPlugin().getConfigCache().getNo_permission(); BaseComponent[] component = TextComponent.fromLegacyText(message); sender.spigot().sendMessage(component); return; @@ -147,11 +147,11 @@ public static void disable(CommandSender sender, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (CombatTimer.isInCombat(player.getUniqueId())) { - sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getCant_do_that_during_combat())); + sender.sendMessage(PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getCant_do_that_during_combat())); return; } - TogglePvP.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), false); - String message = PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getPvp_disabled()); + TogglePvp.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), false); + String message = PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getPvp_disabled()); BaseComponent[] component = TextComponent.fromLegacyText(message); player.spigot().sendMessage(ChatMessageType.CHAT, component); } else { @@ -159,7 +159,7 @@ public static void disable(CommandSender sender, String[] args) { } } else if (args.length == 2) { if (!sender.hasPermission("togglepvp.command.toggle.others")) { - String message = TogglePvP.getPlugin().getConfigCache().getNo_permission(); + String message = TogglePvp.getPlugin().getConfigCache().getNo_permission(); BaseComponent[] component = TextComponent.fromLegacyText(message); sender.spigot().sendMessage(component); return; @@ -167,15 +167,15 @@ public static void disable(CommandSender sender, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (CombatTimer.isInCombat(player.getUniqueId())) { - sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getCant_do_that_during_combat())); + sender.sendMessage(PluginMessages.parseMessage(TogglePvp.getPlugin().getConfigCache().getCant_do_that_during_combat())); return; } } try { Player player = Bukkit.getPlayer(args[1]); - String message = TogglePvP.getPlugin().getConfigCache().getPvp_disabled_other(); + String message = TogglePvp.getPlugin().getConfigCache().getPvp_disabled_other(); sender.sendMessage(PluginMessages.parsePlayerName(player, message)); - TogglePvP.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true); + TogglePvp.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true); } catch (NullPointerException e) { sender.sendMessage(PluginMessages.parseMessage("&cPlayer offline.")); } diff --git a/src/main/java/eu/endermite/togglepvp/commands/ReloadCommand.java b/src/main/java/eu/endermite/togglepvp/commands/ReloadCommand.java index 5e782a5..dd0284d 100644 --- a/src/main/java/eu/endermite/togglepvp/commands/ReloadCommand.java +++ b/src/main/java/eu/endermite/togglepvp/commands/ReloadCommand.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.commands; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -10,14 +10,14 @@ public class ReloadCommand { public static void reload(CommandSender sender) { - Bukkit.getScheduler().runTaskAsynchronously(TogglePvP.getPlugin(), () -> { + Bukkit.getScheduler().runTaskAsynchronously(TogglePvp.getPlugin(), () -> { if (!sender.hasPermission("togglepvp.command.reload")) { - String message = TogglePvP.getPlugin().getConfigCache().getNo_permission(); + String message = TogglePvp.getPlugin().getConfigCache().getNo_permission(); BaseComponent[] component = TextComponent.fromLegacyText(message); sender.spigot().sendMessage(component); return; } - TogglePvP.getPlugin().reloadPluginConfig(sender); + TogglePvp.getPlugin().reloadPluginConfig(sender); }); } diff --git a/src/main/java/eu/endermite/togglepvp/config/ConfigCache.java b/src/main/java/eu/endermite/togglepvp/config/ConfigCache.java index 3100edc..29004e1 100644 --- a/src/main/java/eu/endermite/togglepvp/config/ConfigCache.java +++ b/src/main/java/eu/endermite/togglepvp/config/ConfigCache.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.config; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import lombok.Getter; import org.bukkit.configuration.Configuration; @@ -31,7 +31,7 @@ public class ConfigCache { public ConfigCache() { - Configuration config = TogglePvP.getPlugin().getConfig(); + Configuration config = TogglePvp.getPlugin().getConfig(); // Settings this.pvp_enabled_by_default = config.getBoolean("settings.pvp_enabled_by_default", false); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerAttackListener.java b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerAttackListener.java index e0d58de..865857e 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerAttackListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerAttackListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.player; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.util.CombatTimer; import eu.endermite.togglepvp.util.PluginMessages; @@ -25,10 +25,10 @@ public void onPlayerAttack(org.bukkit.event.entity.EntityDamageByEntityEvent eve Player damager = (Player) damagerEntity; Player victim = (Player) victimEntity; - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!damagerPvpEnabled) { event.setCancelled(true); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByExplosionListener.java b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByExplosionListener.java index 5e740aa..1f1edea 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByExplosionListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByExplosionListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.player; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.CombatTimer; @@ -30,14 +30,14 @@ public void onPlayerHitByExplosion(org.bukkit.event.entity.EntityDamageByEntityE try { UUID damageruuid = UUID.fromString(event.getDamager().getMetadata("PLAYEREXPLODED").get(0).asString()); if (!victim.getUniqueId().equals(damageruuid)) { - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); boolean damagerPvpEnabled = SmartCache.getPlayerData(damageruuid).isPvpEnabled(); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damageruuid, config.getCannot_attack_attacker()); event.setCancelled(true); return; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { PluginMessages.sendActionBar(damageruuid, config.getCannot_attack_victim()); event.setCancelled(true); @@ -58,12 +58,12 @@ public void onPlayerHitEnderCrystal(org.bukkit.event.entity.EntityDamageByEntity if (event.getEntity() instanceof EnderCrystal) { EnderCrystal enderCrystal = (EnderCrystal) event.getEntity(); if (event.getDamager() instanceof Player) { - enderCrystal.setMetadata("PLAYEREXPLODED", new FixedMetadataValue(TogglePvP.getPlugin(), event.getDamager().getUniqueId().toString())); + enderCrystal.setMetadata("PLAYEREXPLODED", new FixedMetadataValue(TogglePvp.getPlugin(), event.getDamager().getUniqueId().toString())); } else if (event.getDamager() instanceof Projectile) { Projectile projectile = (Projectile) event.getDamager(); if (projectile.getShooter() instanceof Player) { Player damager = (Player) projectile.getShooter(); - enderCrystal.setMetadata("PLAYEREXPLODED", new FixedMetadataValue(TogglePvP.getPlugin(), damager.getUniqueId().toString())); + enderCrystal.setMetadata("PLAYEREXPLODED", new FixedMetadataValue(TogglePvp.getPlugin(), damager.getUniqueId().toString())); } } } @@ -78,12 +78,12 @@ public void onPlayerPrimedTnt(org.bukkit.event.entity.ExplosionPrimeEvent event) TNTPrimed tntPrimed = (TNTPrimed) event.getEntity(); if (tntPrimed.getSource() instanceof Player) { Player damager = (Player) tntPrimed.getSource(); - tntPrimed.setMetadata("PLAYEREXPLODED",new FixedMetadataValue( TogglePvP.getPlugin(), damager.getUniqueId().toString())); + tntPrimed.setMetadata("PLAYEREXPLODED",new FixedMetadataValue( TogglePvp.getPlugin(), damager.getUniqueId().toString())); } else if (tntPrimed.getSource() instanceof TNTPrimed) { try { TNTPrimed sourceTnt = (TNTPrimed) tntPrimed.getSource(); String damagerUuid = sourceTnt.getMetadata("PLAYEREXPLODED").get(0).asString(); - tntPrimed.setMetadata("PLAYEREXPLODED", new FixedMetadataValue( TogglePvP.getPlugin(), damagerUuid)); + tntPrimed.setMetadata("PLAYEREXPLODED", new FixedMetadataValue( TogglePvp.getPlugin(), damagerUuid)); }catch (NullPointerException ignored) {} } } @@ -97,7 +97,7 @@ public void onPlayerPrimedTnt(org.bukkit.event.entity.ExplosionPrimeEvent event) public void onPlayerPlacedTntMinecart(org.bukkit.event.entity.EntityPlaceEvent event) { if (event.getEntityType().equals(EntityType.MINECART_TNT)) { if (event.getPlayer() != null) { - event.getEntity().setMetadata("PLAYEREXPLODED", new FixedMetadataValue( TogglePvP.getPlugin(), event.getPlayer().getUniqueId().toString())); + event.getEntity().setMetadata("PLAYEREXPLODED", new FixedMetadataValue( TogglePvp.getPlugin(), event.getPlayer().getUniqueId().toString())); } } } @@ -109,7 +109,7 @@ public void onPlayerPlacedTntMinecart(org.bukkit.event.entity.EntityPlaceEvent e public void onPlayerNudgedTntMinecart(org.bukkit.event.vehicle.VehicleEntityCollisionEvent event) { if (event.getVehicle() instanceof ExplosiveMinecart && event.getEntity() instanceof Player) { Player damager = (Player) event.getEntity(); - event.getVehicle().setMetadata("PLAYEREXPLODED", new FixedMetadataValue( TogglePvP.getPlugin(), damager.getUniqueId().toString())); + event.getVehicle().setMetadata("PLAYEREXPLODED", new FixedMetadataValue( TogglePvp.getPlugin(), damager.getUniqueId().toString())); } } diff --git a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByFireworkListener.java b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByFireworkListener.java index 96d54c6..c5ffad4 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByFireworkListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByFireworkListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.player; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.util.CombatTimer; import eu.endermite.togglepvp.util.PluginMessages; import org.bukkit.entity.Firework; @@ -22,16 +22,16 @@ public void onFireworkDamage(org.bukkit.event.entity.EntityDamageByEntityEvent e if (damager == victim) { return; } - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!damagerPvpEnabled) { event.setCancelled(true); - PluginMessages.sendActionBar(damager.getUniqueId(), TogglePvP.getPlugin().getConfigCache().getCannot_attack_attacker()); + PluginMessages.sendActionBar(damager.getUniqueId(), TogglePvp.getPlugin().getConfigCache().getCannot_attack_attacker()); return; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { event.setCancelled(true); - PluginMessages.sendActionBar(damager.getUniqueId(), TogglePvP.getPlugin().getConfigCache().getCannot_attack_victim()); + PluginMessages.sendActionBar(damager.getUniqueId(), TogglePvp.getPlugin().getConfigCache().getCannot_attack_victim()); return; } CombatTimer.refreshPlayersCombatTime(damager.getUniqueId(), victim.getUniqueId()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByProjectileListener.java b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByProjectileListener.java index a65b5d4..380899e 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByProjectileListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitByProjectileListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.player; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.util.CombatTimer; import eu.endermite.togglepvp.util.PluginMessages; @@ -29,9 +29,9 @@ public void onPlayerHitProjectile(org.bukkit.event.entity.EntityDamageByEntityEv if (damager == victim) { return; } - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!damagerPvpEnabled) { event.setCancelled(true); PluginMessages.sendActionBar(damager, config.getCannot_attack_attacker()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitBySplashPotionListener.java b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitBySplashPotionListener.java index f426df0..4fc098b 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitBySplashPotionListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerHitBySplashPotionListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.player; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.util.CombatTimer; import eu.endermite.togglepvp.util.PluginMessages; @@ -48,14 +48,14 @@ public void onPlayerHitBySplashPotion(org.bukkit.event.entity.PotionSplashEvent if (damager == victim) continue; - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { event.setIntensity(victim, 0); PluginMessages.sendActionBar(damager, config.getCannot_attack_attacker()); continue; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { event.setIntensity(victim, 0); PluginMessages.sendActionBar(damager, config.getCannot_attack_victim()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerJoinAndLeaveListener.java b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerJoinAndLeaveListener.java index 7ffba3d..d66ddfb 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerJoinAndLeaveListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/player/PlayerJoinAndLeaveListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.player; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.players.PlayerData; import eu.endermite.togglepvp.util.PluginMessages; import org.bukkit.entity.Player; @@ -17,8 +17,8 @@ public class PlayerJoinAndLeaveListener implements Listener { public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) { Player player = event.getPlayer(); - PlayerData playerData = TogglePvP.getPlugin().getSqLite().getPlayerInfo(player.getUniqueId()); - TogglePvP.getPlugin().getPlayerManager().addPlayer(player.getUniqueId(), playerData); + PlayerData playerData = TogglePvp.getPlugin().getSqLite().getPlayerInfo(player.getUniqueId()); + TogglePvp.getPlugin().getPlayerManager().addPlayer(player.getUniqueId(), playerData); } /** * This event is here to dump player's saved options from memory @@ -27,16 +27,16 @@ public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) { @EventHandler public void onPlayerLeave(org.bukkit.event.player.PlayerQuitEvent event) { Player player = event.getPlayer(); - TogglePvP.getPlugin().getSqLite().updatePlayerInfo(player.getUniqueId(), TogglePvP.getPlugin().getPlayerManager().getPlayer(player.getUniqueId())); - if (TogglePvP.getPlugin().getConfigCache().isPunish_for_combat_logout()) { + TogglePvp.getPlugin().getSqLite().updatePlayerInfo(player.getUniqueId(), TogglePvp.getPlugin().getPlayerManager().getPlayer(player.getUniqueId())); + if (TogglePvp.getPlugin().getConfigCache().isPunish_for_combat_logout()) { long now = Instant.now().getEpochSecond(); - long combatTime = TogglePvP.getPlugin().getPlayerManager().getPlayer(player.getUniqueId()).getCombattime(); + long combatTime = TogglePvp.getPlugin().getPlayerManager().getPlayer(player.getUniqueId()).getCombattime(); if (combatTime > now) { player.setHealth(0); - if (TogglePvP.getPlugin().getConfigCache().isPunish_for_combat_logout_announce()) { - PluginMessages.broadcastMessage(player, TogglePvP.getPlugin().getConfigCache().getPunish_for_combat_logout_message()); + if (TogglePvp.getPlugin().getConfigCache().isPunish_for_combat_logout_announce()) { + PluginMessages.broadcastMessage(player, TogglePvp.getPlugin().getConfigCache().getPunish_for_combat_logout_message()); } - TogglePvP.getPlugin().getPlayerManager().getPlayer(player.getUniqueId()).setCombattime(now-1); + TogglePvp.getPlugin().getPlayerManager().getPlayer(player.getUniqueId()).setCombattime(now-1); } } } diff --git a/src/main/java/eu/endermite/togglepvp/listeners/player/WolfAttackPlayerListener.java b/src/main/java/eu/endermite/togglepvp/listeners/player/WolfAttackPlayerListener.java index 45f7821..4222997 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/player/WolfAttackPlayerListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/player/WolfAttackPlayerListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.player; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.CombatTimer; import org.bukkit.entity.Player; @@ -24,7 +24,7 @@ public void onWolfAttack(org.bukkit.event.entity.EntityDamageByEntityEvent event try { boolean damagerPvpEnabled = SmartCache.getPlayerData(wolf.getOwner().getUniqueId()).isPvpEnabled(); Player victim = (Player) event.getEntity(); - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled || !damagerPvpEnabled) { wolf.setAngry(false); event.setCancelled(true); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/AreaEffectCloudApplyListener.java b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/AreaEffectCloudApplyListener.java index 6d1282e..fb56cb0 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/AreaEffectCloudApplyListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/AreaEffectCloudApplyListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.unspecific; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.CombatTimer; @@ -46,14 +46,14 @@ public void onCloudEffects(AreaEffectCloudApplyEvent event) { if (damager == victim) continue; - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { it.remove(); PluginMessages.sendActionBar(damager, config.getCannot_attack_attacker()); continue; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { it.remove(); PluginMessages.sendActionBar(damager, config.getCannot_attack_victim()); @@ -65,8 +65,8 @@ public void onCloudEffects(AreaEffectCloudApplyEvent event) { if (victim.getOwner() == null || victim.getOwner() == damager) { return; } - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { it.remove(); PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/EntityHitByLightningListener.java b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/EntityHitByLightningListener.java index 73d1d48..cd7aac6 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/EntityHitByLightningListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/EntityHitByLightningListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.unspecific; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.players.SmartCache; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; @@ -26,7 +26,7 @@ public void onPlayerLightningDamage(org.bukkit.event.entity.EntityDamageByEntity if (event.getDamager() instanceof LightningStrike && event.getDamager().getMetadata("TRIDENT").size() >= 1) { if (event.getEntity() instanceof Player) { Player victim = (Player) event.getEntity(); - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { event.setCancelled(true); } @@ -46,11 +46,11 @@ public void onPlayerLightningDamage(org.bukkit.event.entity.EntityDamageByEntity @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onLightningStrike(LightningStrikeEvent event){ if(event.getCause() == LightningStrikeEvent.Cause.TRIDENT){ - if (TogglePvP.getPlugin().getConfigCache().isChanneling_enchant_disabled()) { + if (TogglePvp.getPlugin().getConfigCache().isChanneling_enchant_disabled()) { event.setCancelled(true); return; } - event.getLightning().setMetadata("TRIDENT", new FixedMetadataValue(TogglePvP.getPlugin(), event.getLightning().getLocation())); + event.getLightning().setMetadata("TRIDENT", new FixedMetadataValue(TogglePvp.getPlugin(), event.getLightning().getLocation())); } } } diff --git a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/FishingListener.java b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/FishingListener.java index 9469ad0..197e64c 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/FishingListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/FishingListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.unspecific; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.CombatTimer; @@ -14,7 +14,7 @@ @eu.endermite.togglepvp.util.Listener public class FishingListener implements Listener { - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); /** * Prevents hooking players with disabled pvp with fishing rod @@ -27,13 +27,13 @@ public void onFish(org.bukkit.event.player.PlayerFishEvent event) { if (damager == victim) { return; } - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { event.setCancelled(true); PluginMessages.sendActionBar(damager, config.getCannot_attack_attacker()); return; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { event.setCancelled(true); PluginMessages.sendActionBar(damager, config.getCannot_attack_victim()); @@ -46,7 +46,7 @@ public void onFish(org.bukkit.event.player.PlayerFishEvent event) { if (victim.getOwner() == null || victim.getOwner() == damager) { return; } - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { event.setCancelled(true); PluginMessages.sendActionBar(damager, config.getCannot_attack_attacker()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/LavaDumpAndIgniteListener.java b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/LavaDumpAndIgniteListener.java index 21357cf..538ab3e 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/LavaDumpAndIgniteListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/LavaDumpAndIgniteListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.unspecific; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.BoundingBoxUtil; @@ -20,7 +20,7 @@ @eu.endermite.togglepvp.util.Listener public class LavaDumpAndIgniteListener implements Listener { - private ConfigCache config = TogglePvP.getPlugin().getConfigCache(); + private ConfigCache config = TogglePvp.getPlugin().getConfigCache(); /** * Prevents dumping lava and pufferfish bucket near players with pvp off @@ -28,7 +28,7 @@ public class LavaDumpAndIgniteListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onLavaDump(org.bukkit.event.player.PlayerBucketEmptyEvent event) { - if (!TogglePvP.getPlugin().getConfigCache().isLava_and_fire_stopper_enabled()) + if (!TogglePvp.getPlugin().getConfigCache().isLava_and_fire_stopper_enabled()) return; if (event.getBucket().equals(Material.LAVA_BUCKET) || event.getBucket().equals(Material.PUFFERFISH_BUCKET)) { @@ -40,13 +40,13 @@ public void onLavaDump(org.bukkit.event.player.PlayerBucketEmptyEvent event) { if (entity instanceof Player) { Player victim = (Player) entity; if (victim != damager) { - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_attacker()); event.setCancelled(true); return; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_victim()); event.setCancelled(true); @@ -59,7 +59,7 @@ public void onLavaDump(org.bukkit.event.player.PlayerBucketEmptyEvent event) { if (victim.getOwner() == null) { return; } - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker()); event.setCancelled(true); @@ -85,7 +85,7 @@ public void onLavaDump(org.bukkit.event.player.PlayerBucketEmptyEvent event) { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onIgnite(org.bukkit.event.block.BlockIgniteEvent event) { - if (!TogglePvP.getPlugin().getConfigCache().isLava_and_fire_stopper_enabled()) + if (!TogglePvp.getPlugin().getConfigCache().isLava_and_fire_stopper_enabled()) return; if (event.getPlayer() !=null) { @@ -97,13 +97,13 @@ public void onIgnite(org.bukkit.event.block.BlockIgniteEvent event) { if (entity instanceof Player) { Player victim = (Player) entity; if (victim != damager) { - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_attacker()); event.setCancelled(true); return; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_victim()); event.setCancelled(true); @@ -116,7 +116,7 @@ public void onIgnite(org.bukkit.event.block.BlockIgniteEvent event) { if (victim.getOwner() == null || victim.getOwner() == damager) { return; } - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker()); event.setCancelled(true); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/LightningBlockIgniteListener.java b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/LightningBlockIgniteListener.java index 1fe9290..d72ac2a 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/LightningBlockIgniteListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/LightningBlockIgniteListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.unspecific; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.players.SmartCache; import org.bukkit.entity.Entity; import org.bukkit.entity.LightningStrike; @@ -25,7 +25,7 @@ public void onBlockIgnite(org.bukkit.event.block.BlockIgniteEvent event) { for (Entity entity : lightningStrike.getNearbyEntities(2,2,2)) { if (entity instanceof Player) { Player victim = (Player) entity; - if (!TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId())) { + if (!TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId())) { event.setCancelled(true); return; } diff --git a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/PlaceWitherRoseListener.java b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/PlaceWitherRoseListener.java index 4b91f9a..ccd1be5 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/unspecific/PlaceWitherRoseListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/unspecific/PlaceWitherRoseListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.unspecific; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.BoundingBoxUtil; @@ -19,11 +19,11 @@ @eu.endermite.togglepvp.util.Listener public class PlaceWitherRoseListener implements Listener { - private ConfigCache config = TogglePvP.getPlugin().getConfigCache(); + private ConfigCache config = TogglePvp.getPlugin().getConfigCache(); @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerWitherRosePlace(org.bukkit.event.block.BlockPlaceEvent event) { - if (!TogglePvP.getPlugin().getConfigCache().isLava_and_fire_stopper_enabled()) + if (!TogglePvp.getPlugin().getConfigCache().isLava_and_fire_stopper_enabled()) return; if(event.getBlock().getType().equals(Material.WITHER_ROSE)) { @@ -35,13 +35,13 @@ public void onPlayerWitherRosePlace(org.bukkit.event.block.BlockPlaceEvent event Player damager = event.getPlayer(); Player victim = (Player) entity; if (victim != damager) { - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_attacker()); event.setCancelled(true); return; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_victim()); event.setCancelled(true); @@ -55,7 +55,7 @@ public void onPlayerWitherRosePlace(org.bukkit.event.block.BlockPlaceEvent event if (victim.getOwner() == null || victim.getOwner() == damager) { return; } - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker()); event.setCancelled(true); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/wolf/PlayerAttackWolfListener.java b/src/main/java/eu/endermite/togglepvp/listeners/wolf/PlayerAttackWolfListener.java index aa607cb..6e44326 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/wolf/PlayerAttackWolfListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/wolf/PlayerAttackWolfListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.wolf; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.CombatTimer; @@ -26,8 +26,8 @@ public void onPlayerAttackWolf(org.bukkit.event.entity.EntityDamageByEntityEvent return; } - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); - boolean damagerPvpState = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); + boolean damagerPvpState = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpState) { PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/wolf/PlayerHitWolfWithProjectile.java b/src/main/java/eu/endermite/togglepvp/listeners/wolf/PlayerHitWolfWithProjectile.java index 7efbc9a..ac5c310 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/wolf/PlayerHitWolfWithProjectile.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/wolf/PlayerHitWolfWithProjectile.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.wolf; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.CombatTimer; @@ -28,8 +28,8 @@ public void onPlayerHitWolfWithProjectile(org.bukkit.event.entity.EntityDamageBy if (victim.getOwner() == null || victim.getOwner() == damager) { return; } - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); boolean victimPvpEnabled = SmartCache.getPlayerData(victim.getOwner().getUniqueId()).isPvpEnabled(); if (!damagerPvpEnabled) { event.setCancelled(true); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitByExplosionListener.java b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitByExplosionListener.java index 4ad1257..f8460ef 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitByExplosionListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitByExplosionListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.wolf; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.CombatTimer; @@ -33,7 +33,7 @@ public void onPlayerHitByExplosion(org.bukkit.event.entity.EntityDamageByEntityE if (victim.getOwner().getUniqueId() == damageruuid) { return; } - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); boolean damagerPvpEnabled = SmartCache.getPlayerData(damageruuid).isPvpEnabled(); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damageruuid, config.getCannot_attack_pets_attacker()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitByFireworkListener.java b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitByFireworkListener.java index f7dad77..0d0004a 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitByFireworkListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitByFireworkListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.wolf; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.util.CombatTimer; import eu.endermite.togglepvp.util.PluginMessages; import org.bukkit.entity.Firework; @@ -24,16 +24,16 @@ public void onFireworkDamage(org.bukkit.event.entity.EntityDamageByEntityEvent e Player damager = (Player) firework.getShooter(); if (victim.getOwner() == damager) return; - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getOwner().getUniqueId()); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getOwner().getUniqueId()); if (!damagerPvpEnabled) { event.setCancelled(true); - PluginMessages.sendActionBar(damager.getUniqueId(), TogglePvP.getPlugin().getConfigCache().getCannot_attack_pets_attacker()); + PluginMessages.sendActionBar(damager.getUniqueId(), TogglePvp.getPlugin().getConfigCache().getCannot_attack_pets_attacker()); return; } - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!victimPvpEnabled) { event.setCancelled(true); - PluginMessages.sendActionBar(damager.getUniqueId(), TogglePvP.getPlugin().getConfigCache().getCannot_attack_pets_victim()); + PluginMessages.sendActionBar(damager.getUniqueId(), TogglePvp.getPlugin().getConfigCache().getCannot_attack_pets_victim()); return; } CombatTimer.refreshPlayersCombatTime(damager.getUniqueId(), victim.getOwner().getUniqueId()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitBySplashPotionListener.java b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitBySplashPotionListener.java index 1d80602..f480ec8 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitBySplashPotionListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfHitBySplashPotionListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.wolf; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.CombatTimer; @@ -51,8 +51,8 @@ public void onWolfHitBySplashPotion(org.bukkit.event.entity.PotionSplashEvent ev if (victim.getOwner() == null || victim.getOwner() == damager) continue; - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); - boolean damagerPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); + boolean damagerPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(damager.getUniqueId()); if (!damagerPvpEnabled) { event.setIntensity(victim, 0); PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfLeashListener.java b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfLeashListener.java index 02a47f1..ac4c79c 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfLeashListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfLeashListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.wolf; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.config.ConfigCache; import eu.endermite.togglepvp.players.SmartCache; import eu.endermite.togglepvp.util.PluginMessages; @@ -24,7 +24,7 @@ public void onWolfLeash(org.bukkit.event.entity.PlayerLeashEntityEvent event) { if (victim.getOwner() == damager) { return; } - ConfigCache config = TogglePvP.getPlugin().getConfigCache(); + ConfigCache config = TogglePvp.getPlugin().getConfigCache(); boolean damagerPvpEnabled = SmartCache.getPlayerData(damager.getUniqueId()).isPvpEnabled(); if (!damagerPvpEnabled) { PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker()); diff --git a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfTargettingPlayerListener.java b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfTargettingPlayerListener.java index 2153d37..3e40ac2 100644 --- a/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfTargettingPlayerListener.java +++ b/src/main/java/eu/endermite/togglepvp/listeners/wolf/WolfTargettingPlayerListener.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.listeners.wolf; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.players.SmartCache; import org.bukkit.entity.Player; import org.bukkit.entity.Wolf; @@ -21,7 +21,7 @@ public void onWolfTarget(org.bukkit.event.entity.EntityTargetEvent event) { if (event.getTarget() instanceof Player) { boolean attackerPvPEnabled = SmartCache.getPlayerData(wolf.getOwner().getUniqueId()).isPvpEnabled(); Player victim = (Player) event.getTarget(); - boolean victimPvpEnabled = TogglePvP.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); + boolean victimPvpEnabled = TogglePvp.getPlugin().getPlayerManager().getPlayerPvPState(victim.getUniqueId()); if (!attackerPvPEnabled || !victimPvpEnabled) { event.setCancelled(true); } diff --git a/src/main/java/eu/endermite/togglepvp/players/PlayerData.java b/src/main/java/eu/endermite/togglepvp/players/PlayerData.java index bac14ce..521fe95 100644 --- a/src/main/java/eu/endermite/togglepvp/players/PlayerData.java +++ b/src/main/java/eu/endermite/togglepvp/players/PlayerData.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.players; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import java.time.Instant; @@ -28,7 +28,7 @@ public long getCachetime() { } public void refreshCachetime() { - this.cachetime = Instant.now().getEpochSecond()+TogglePvP.getPlugin().getConfigCache().getCache_time(); + this.cachetime = Instant.now().getEpochSecond()+ TogglePvp.getPlugin().getConfigCache().getCache_time(); } public long getCombattime() { @@ -40,6 +40,6 @@ public void setCombattime(long combattime) { } public void refreshCombatTime() { - this.combattime = Instant.now().getEpochSecond()+TogglePvP.getPlugin().getConfigCache().getCombat_time(); + this.combattime = Instant.now().getEpochSecond()+ TogglePvp.getPlugin().getConfigCache().getCombat_time(); } } diff --git a/src/main/java/eu/endermite/togglepvp/players/PlayerManager.java b/src/main/java/eu/endermite/togglepvp/players/PlayerManager.java index 3ce2aa6..335035e 100644 --- a/src/main/java/eu/endermite/togglepvp/players/PlayerManager.java +++ b/src/main/java/eu/endermite/togglepvp/players/PlayerManager.java @@ -1,11 +1,9 @@ package eu.endermite.togglepvp.players; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.entity.Player; - -import java.time.Instant; import java.util.HashMap; import java.util.UUID; @@ -15,22 +13,11 @@ public class PlayerManager { public PlayerManager() { for (Player p : Bukkit.getOnlinePlayers()) { - PlayerData playerData = TogglePvP.getPlugin().getSqLite().getPlayerInfo(p.getUniqueId()); + PlayerData playerData = TogglePvp.getPlugin().getSqLite().getPlayerInfo(p.getUniqueId()); playerList.put(p.getUniqueId(), playerData); } } - - public long refreshedCacheTime() { - long cacheTime = TogglePvP.getPlugin().getConfigCache().getCache_time(); - return Instant.now().getEpochSecond()+cacheTime; - } - - public long refreshedCombatTime() { - long combatTime = TogglePvP.getPlugin().getConfigCache().getCombat_time(); - return Instant.now().getEpochSecond()+combatTime; - } - public void refreshPlayersCacheTime(UUID uuid) { playerList.get(uuid).refreshCachetime(); } @@ -62,7 +49,7 @@ public void setPlayerPvpState(UUID uuid, boolean state) { } public boolean togglePlayerPvpState(UUID uuid) { - boolean currentState = (boolean) playerList.get(uuid).isPvpEnabled(); + boolean currentState = playerList.get(uuid).isPvpEnabled(); if (currentState) { playerList.get(uuid).setPvpEnabled(false); return false; diff --git a/src/main/java/eu/endermite/togglepvp/players/SmartCache.java b/src/main/java/eu/endermite/togglepvp/players/SmartCache.java index 455bc6b..53f4980 100644 --- a/src/main/java/eu/endermite/togglepvp/players/SmartCache.java +++ b/src/main/java/eu/endermite/togglepvp/players/SmartCache.java @@ -1,6 +1,6 @@ package eu.endermite.togglepvp.players; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.time.Instant; @@ -10,20 +10,21 @@ public class SmartCache { public static void runSmartCache() { - Bukkit.getScheduler().runTaskTimerAsynchronously(TogglePvP.getPlugin(), () -> { + Bukkit.getScheduler().runTaskTimerAsynchronously(TogglePvp.getPlugin(), () -> { // Refresh cache timer if player is online - for (Map.Entry e : TogglePvP.getPlugin().getPlayerManager().getPlayerList().entrySet()) { + for (Map.Entry e : TogglePvp.getPlugin().getPlayerManager().getPlayerList().entrySet()) { try { Player player = Bukkit.getPlayer(e.getKey()); if (player != null && player.isOnline()) { - TogglePvP.getPlugin().getPlayerManager().refreshPlayersCacheTime(e.getKey()); + TogglePvp.getPlugin().getPlayerManager().refreshPlayersCacheTime(e.getKey()); } } catch (NullPointerException ignored) {} } // Check for entries that should be invalidated try { long now = Instant.now().getEpochSecond(); - TogglePvP.getPlugin().getPlayerManager().getPlayerList().entrySet().removeIf(cacheEntry -> cacheEntry.getValue().getCachetime() < now); + TogglePvp.getPlugin().getPlayerManager().getPlayerList().entrySet() + .removeIf(cacheEntry -> cacheEntry.getValue().getCachetime() < now); } catch (Exception ignored) {} }, 100, 100); } @@ -31,13 +32,13 @@ public static void runSmartCache() { public static PlayerData getPlayerData(UUID uuid) { // Try to get data from cache and refresh it try { - TogglePvP.getPlugin().getPlayerManager().refreshPlayersCacheTime(uuid); - return TogglePvP.getPlugin().getPlayerManager().getPlayer(uuid); + TogglePvp.getPlugin().getPlayerManager().refreshPlayersCacheTime(uuid); + return TogglePvp.getPlugin().getPlayerManager().getPlayer(uuid); } catch (NullPointerException e) { // If player data is not in cache get it from database and put into cache try { - PlayerData playerData = TogglePvP.getPlugin().getSqLite().getPlayerInfo(uuid); - TogglePvP.getPlugin().getPlayerManager().addPlayer(uuid, playerData); + PlayerData playerData = TogglePvp.getPlugin().getSqLite().getPlayerInfo(uuid); + TogglePvp.getPlugin().getPlayerManager().addPlayer(uuid, playerData); return playerData; } catch (NullPointerException ex) { // Return false if database call fails @@ -46,5 +47,14 @@ public static PlayerData getPlayerData(UUID uuid) { } } + public static void setPlayerPvpState(UUID uuid, boolean state) { + // If player is in cache update that + if (TogglePvp.getPlugin().getPlayerManager().getPlayer(uuid) != null) { + TogglePvp.getPlugin().getPlayerManager().getPlayer(uuid).setPvpEnabled(state); + } + // Update the database aswell + TogglePvp.getPlugin().getSqLite().updatePlayerInfo(uuid, new PlayerData(state)); + } + } diff --git a/src/main/java/eu/endermite/togglepvp/util/CombatTimer.java b/src/main/java/eu/endermite/togglepvp/util/CombatTimer.java index 1b4c846..b2c2835 100644 --- a/src/main/java/eu/endermite/togglepvp/util/CombatTimer.java +++ b/src/main/java/eu/endermite/togglepvp/util/CombatTimer.java @@ -1,8 +1,7 @@ package eu.endermite.togglepvp.util; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.players.SmartCache; - import java.time.Instant; import java.util.UUID; @@ -13,9 +12,9 @@ public static void refreshPlayersCombatTime(UUID uuid) { long now = Instant.now().getEpochSecond(); long combattime = SmartCache.getPlayerData(uuid).getCombattime(); if (combattime < now) { - PluginMessages.sendActionBar(uuid, TogglePvP.getPlugin().getConfigCache().getEntering_combat()); + PluginMessages.sendActionBar(uuid, TogglePvp.getPlugin().getConfigCache().getEntering_combat()); } - TogglePvP.getPlugin().getPlayerManager().refreshPlayersCombatTime(uuid); + TogglePvp.getPlugin().getPlayerManager().refreshPlayersCombatTime(uuid); } catch (Exception ignored) {} } @@ -32,8 +31,6 @@ public static boolean isInCombat(UUID uuid) { } catch (Exception e) { return false; } - - } } diff --git a/src/main/java/eu/endermite/togglepvp/util/DatabaseSQLite.java b/src/main/java/eu/endermite/togglepvp/util/DatabaseSQLite.java index b6fdcdb..f024ca6 100644 --- a/src/main/java/eu/endermite/togglepvp/util/DatabaseSQLite.java +++ b/src/main/java/eu/endermite/togglepvp/util/DatabaseSQLite.java @@ -1,11 +1,10 @@ package eu.endermite.togglepvp.util; -import eu.endermite.togglepvp.TogglePvP; +import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.players.PlayerData; import java.io.File; import java.sql.*; -import java.util.HashMap; import java.util.UUID; public class DatabaseSQLite { @@ -62,7 +61,7 @@ public PlayerData getPlayerInfo(UUID uuid) { Connection conn = DriverManager.getConnection(url); Statement insertnewuser = conn.createStatement(); try { - String newuserdata = "INSERT OR IGNORE INTO `players` (player_uuid, pvpenabled) VALUES ('" + uuid.toString() + "', " + TogglePvP.getPlugin().getConfigCache().isPvp_enabled_by_default() + ")"; + String newuserdata = "INSERT OR IGNORE INTO `players` (player_uuid, pvpenabled) VALUES ('" + uuid.toString() + "', " + TogglePvp.getPlugin().getConfigCache().isPvp_enabled_by_default() + ")"; insertnewuser.execute(newuserdata); } catch (SQLException e) { if (e.getErrorCode() != 19) { @@ -82,7 +81,6 @@ public PlayerData getPlayerInfo(UUID uuid) { } public void updatePlayerInfo(UUID uuid, PlayerData data) { - try { Connection conn = DriverManager.getConnection(url); Statement insertnewuser = conn.createStatement(); @@ -90,7 +88,7 @@ public void updatePlayerInfo(UUID uuid, PlayerData data) { String newuserdata = "UPDATE `players` SET pvpenabled = "+data.isPvpEnabled()+" WHERE `player_uuid` = '"+uuid.toString()+"';"; insertnewuser.execute(newuserdata); } catch (SQLException e) { - TogglePvP.getPlugin().getLogger().severe("Error while saving player data!"); + TogglePvp.getPlugin().getLogger().severe("Error while saving player data!"); e.printStackTrace(); } } catch (SQLException throwables) {