diff --git a/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java b/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java index 220d625..7bebfc2 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java @@ -23,6 +23,7 @@ public class ArmorCommand extends Command { if (sender instanceof Player player) { ItemStack helmet = new ItemStack(Material.LEATHER_HELMET); LeatherArmorMeta helmetdata = (LeatherArmorMeta) helmet.getItemMeta(); + if (helmetdata == null) return; helmetdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Helmet"); helmetdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); helmetdata.setUnbreakable(true); @@ -31,6 +32,7 @@ public class ArmorCommand extends Command { ItemStack cp = new ItemStack(Material.LEATHER_CHESTPLATE); LeatherArmorMeta cpdata = (LeatherArmorMeta) cp.getItemMeta(); + if (cpdata == null) return; cpdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Chestplate"); cpdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); cpdata.setUnbreakable(true); @@ -39,6 +41,7 @@ public class ArmorCommand extends Command { ItemStack leg = new ItemStack(Material.LEATHER_LEGGINGS); LeatherArmorMeta legdata = (LeatherArmorMeta) leg.getItemMeta(); + if (legdata == null) return; legdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Leggings"); legdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); legdata.setUnbreakable(true); @@ -47,6 +50,7 @@ public class ArmorCommand extends Command { ItemStack boot = new ItemStack(Material.LEATHER_BOOTS); LeatherArmorMeta bootdata = (LeatherArmorMeta) boot.getItemMeta(); + if (bootdata == null) return; bootdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Boots"); bootdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); bootdata.setUnbreakable(true); diff --git a/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java b/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java index 3b4ace8..283942c 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java @@ -19,9 +19,8 @@ public class HologramCommand extends Command { String[] ar = new String[]{ChatColor.AQUA + "Hi", ChatColor.DARK_PURPLE + "What", ChatColor.GOLD + "Hello World"}; Location location = player.getLocation(); for (String line : ar) { - ArmorStand stand = location.getWorld().spawn(location.subtract(0, 0.3, 0), ArmorStand.class, armorStand -> { - armorStand.setVisible(false); - }); + ArmorStand stand = location.getWorld().spawn(location.subtract(0, 0.3, 0), ArmorStand.class); + stand.setVisible(false); stand.setGravity(false); stand.setInvulnerable(true); stand.setCustomNameVisible(true); diff --git a/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java b/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java index c0fb3ce..cceb3c9 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java @@ -1,5 +1,6 @@ package me.night.nullvalkyrie.commands; +import me.night.nullvalkyrie.Main; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -22,13 +23,13 @@ public class VanishCommand extends Command { if (vanished.contains(player.getUniqueId())) { vanished.remove(player.getUniqueId()); for (Player target : Bukkit.getOnlinePlayers()) { - target.showPlayer(player); + target.showPlayer(Main.getPlugin(Main.class), player); } player.sendMessage(ChatColor.GREEN + "You are now seen by people"); } else { vanished.add(player.getUniqueId()); for (Player target : Bukkit.getOnlinePlayers()) { - target.hidePlayer(player); + target.hidePlayer(Main.getPlugin(Main.class), player); } player.sendMessage(ChatColor.GREEN + "You are now vanished"); } diff --git a/src/main/java/me/night/nullvalkyrie/database/CustomWeaponsDataManager.java b/src/main/java/me/night/nullvalkyrie/database/CustomWeaponsDataManager.java index 9e05221..970031f 100644 --- a/src/main/java/me/night/nullvalkyrie/database/CustomWeaponsDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/CustomWeaponsDataManager.java @@ -27,7 +27,7 @@ public class CustomWeaponsDataManager { abi.put("Name", ability.getString("Name")); List details = new ArrayList<>(); if (ability.get("Details") != null) - for (String s : (List) ability.get("Details")) details.add(s); + details.addAll((List) ability.get("Details")); abi.put("Details", details); for (String a : properties.keySet()) prop.put(a, properties.get(a)); lores.put("Ability", abi); @@ -49,7 +49,7 @@ public class CustomWeaponsDataManager { for (String i : ing.keySet()) ingredients.put(i, ing.getString(i)); List shapes = new ArrayList<>(); - if (recipe.get("Shapes") != null) for (String s : (List) recipe.get("Shapes")) shapes.add(s); + if (recipe.get("Shapes") != null) shapes.addAll((List) recipe.get("Shapes")); recipes.put("Shape", shapes); recipes.put("Amount", recipe.getInteger("Amount")); recipes.put("Ingredients", ingredients); @@ -83,7 +83,7 @@ public class CustomWeaponsDataManager { abi.put("Name", ability.getString("Name")); List details = new ArrayList<>(); if (ability.get("Details") != null) - for (String s : (List) ability.get("Details")) details.add(s); + details.addAll((List) ability.get("Details")); abi.put("Details", details); for (String a : properties.keySet()) prop.put(a, properties.get(a)); lores.put("Ability", abi); diff --git a/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java b/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java index c18217b..d916d19 100644 --- a/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java @@ -1,7 +1,6 @@ package me.night.nullvalkyrie.database; import com.mongodb.client.MongoCursor; -import com.mongodb.client.model.Filters; import me.night.nullvalkyrie.entities.miners.CryptoMiner; import org.bson.Document; import org.bson.conversions.Bson; @@ -32,23 +31,19 @@ public class MinerDataManager { } public static long getLastClaim(long id) { - try (MongoCursor cursor = DatabaseManager.getMinersDB().find(Filters.eq("ID", id)).cursor()) { - while (cursor.hasNext()) { - Document doc = cursor.next(); - for (String key : doc.keySet()) { - if (key.equals("LastClaim")) return (long) doc.get(key); - } + Document doc = DatabaseManager.getMinersDB().find(new Document("ID", id)).first(); + if (doc != null) { + for (String key : doc.keySet()) { + if (key.equals("LastClaim")) return (long) doc.get(key); } } return 0; } public static CryptoMiner getMiner(long id) { - try (MongoCursor cursor = DatabaseManager.getMinersDB().find(Filters.eq("ID", id)).cursor()) { - while (cursor.hasNext()) { - Document doc = cursor.next(); - return new CryptoMiner(doc.getString("Name"), Material.matchMaterial(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim")); - } + Document doc = DatabaseManager.getMinersDB().find(new Document("ID", id)).first(); + if (doc != null) { + return new CryptoMiner(doc.getString("Name"), Material.matchMaterial(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim")); } return null; } diff --git a/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java b/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java index 0916bc7..8247a06 100644 --- a/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java +++ b/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java @@ -9,7 +9,6 @@ import javax.security.auth.login.LoginException; public class DiscordClientManager { - private JDA jda; public DiscordClientManager() { register(); @@ -19,7 +18,7 @@ public class DiscordClientManager { JDABuilder builder = JDABuilder.createDefault(Main.env.get("DISCORD_TOKEN")); builder.setActivity(Activity.streaming("cath.exe", "https://www.youtube.com/watch?v=YSKDu1gKntY")); try { - jda = builder.build(); + JDA jda = builder.build(); } catch (LoginException e) { e.printStackTrace(); } diff --git a/src/main/java/me/night/nullvalkyrie/events/custom/InteractHologramEvent.java b/src/main/java/me/night/nullvalkyrie/events/custom/InteractHologramEvent.java index 5b802ce..6d8e275 100644 --- a/src/main/java/me/night/nullvalkyrie/events/custom/InteractHologramEvent.java +++ b/src/main/java/me/night/nullvalkyrie/events/custom/InteractHologramEvent.java @@ -8,8 +8,8 @@ import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; public class InteractHologramEvent extends Event implements Cancellable { private boolean isCancelled; - public Player player; - public ArmorStand hologram; + public final Player player; + public final ArmorStand hologram; private static final HandlerList HANDLERS = new HandlerList(); public InteractHologramEvent(Player player, ArmorStand hologram) { this.player = player; diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java index f429351..f672546 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java @@ -230,9 +230,8 @@ public class CustomItemEvents implements Listener { @EventHandler public void onDamage(EntityDamageByEntityEvent e) { - if (e.getEntity() instanceof Player) { - Player player = (Player) e.getEntity(); -// if ((player.getHealth() - e.getDamage()) <= 0) { + if (e.getEntity() instanceof Player player) { + // if ((player.getHealth() - e.getDamage()) <= 0) { // e.setCancelled(true); // Location loc = player.getWorld().getBlockAt(-3, 23, -3).getLocation(); // player.teleport(loc); @@ -335,7 +334,7 @@ public class CustomItemEvents implements Listener { } } - ProtocolManager manager = ProtocolLibrary.getProtocolManager(); + final ProtocolManager manager = ProtocolLibrary.getProtocolManager(); public void sendBlockDamage(Player player, Block block) { Location location = block.getLocation(); diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/DamageEffectEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/DamageEffectEvents.java index b934040..d76848d 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/DamageEffectEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/DamageEffectEvents.java @@ -18,7 +18,7 @@ import java.text.DecimalFormat; import java.util.*; public class DamageEffectEvents implements Listener { - public World world = Bukkit.getWorld("world"); + public final World world = Bukkit.getWorld("world"); public final Map indicators = new HashMap<>(); private final DecimalFormat formatter = new DecimalFormat("#"); diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java index 469f9c6..c37fbc6 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java @@ -15,8 +15,8 @@ import org.bukkit.event.weather.WeatherChangeEvent; import java.io.File; public class ServerEvents implements Listener { - public BossBar bossbar; - public PacketInjector injector; + public final BossBar bossbar; + public final PacketInjector injector; public ServerEvents() { bossbar = Bukkit.createBossBar(ChatColor.GOLD + "Kuudra", BarColor.RED, BarStyle.SEGMENTED_12); this.injector = new PacketInjector(); diff --git a/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java b/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java index 2f79fce..2dabd7a 100644 --- a/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java +++ b/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java @@ -21,7 +21,7 @@ import java.util.*; import static me.night.nullvalkyrie.database.CustomWeaponsDataManager.getWeapon; public class CustomItemManager { - public static HashMap keys = new HashMap<>(); + public static final HashMap keys = new HashMap<>(); public static ItemStack produceItem(String itemName) { HashMap weapon = getWeapon(itemName); diff --git a/src/main/java/me/night/nullvalkyrie/items/Pickaxe.java b/src/main/java/me/night/nullvalkyrie/items/Pickaxe.java index abe63d8..e34be58 100644 --- a/src/main/java/me/night/nullvalkyrie/items/Pickaxe.java +++ b/src/main/java/me/night/nullvalkyrie/items/Pickaxe.java @@ -7,8 +7,8 @@ import org.bukkit.inventory.ItemStack; import java.util.HashMap; public class Pickaxe { - public ArrayListMultimap multimap = ArrayListMultimap.create(); - public HashMap phases = new HashMap<>(); + public final ArrayListMultimap multimap = ArrayListMultimap.create(); + public final HashMap phases = new HashMap<>(); private final ItemStack itemStack; public Pickaxe(ItemStack item) { multimap.put(Material.STONE_PICKAXE, Material.IRON_ORE); //put some blocks and pickaxe to mine diff --git a/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java index 096448b..6aa6475 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java @@ -21,6 +21,7 @@ public class InventoryListener implements Listener { player.sendMessage(ChatColor.RED + "又做兵 抵死"); break; case 22: + player.teleport(player.getWorld().getSpawnLocation()); break; case 24: player.closeInventory(); diff --git a/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java b/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java index 2b5c187..edb8cb5 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java @@ -6,6 +6,8 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scoreboard.*; +import java.util.Objects; + public class NameTagManager { public void setNametags(Player player) { Scoreboard newScoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); @@ -27,8 +29,7 @@ public class NameTagManager { public void newTag(Player player) { Rank rank = RankDataManager.getRank(player.getUniqueId()); for (Player target : Bukkit.getOnlinePlayers()) { - if (rank == null) target.getScoreboard().getTeam(Rank.ROOKIE.name()).addEntry(player.getName()); - else target.getScoreboard().getTeam(rank.name()).addEntry(player.getName()); + target.getScoreboard().getTeam(Objects.requireNonNullElse(rank, Rank.ROOKIE).name()).addEntry(player.getName()); } }