Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Make ViaCommandSender better, fix quite a few of the commands.
Dieser Commit ist enthalten in:
Ursprung
c4ffdc1b7c
Commit
848b0cf113
@ -2,8 +2,11 @@ package us.myles.ViaVersion.bukkit;
|
|||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class BukkitCommandSender implements ViaCommandSender {
|
public class BukkitCommandSender implements ViaCommandSender {
|
||||||
private CommandSender sender;
|
private CommandSender sender;
|
||||||
@ -17,4 +20,18 @@ public class BukkitCommandSender implements ViaCommandSender {
|
|||||||
public void sendMessage(String msg) {
|
public void sendMessage(String msg) {
|
||||||
sender.sendMessage(msg);
|
sender.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUUID() {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
return ((Player) sender).getUniqueId();
|
||||||
|
} else {
|
||||||
|
return UUID.fromString(getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return sender.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
|
|||||||
// Transform
|
// Transform
|
||||||
ByteBuf newPacket = ctx.alloc().buffer();
|
ByteBuf newPacket = ctx.alloc().buffer();
|
||||||
try {
|
try {
|
||||||
if (id == ViaDecodeHandler.PASSTHROUGH_ID) {
|
if (id == PacketWrapper.PASSTHROUGH_ID) {
|
||||||
newPacket.writeBytes(bytebuf);
|
newPacket.writeBytes(bytebuf);
|
||||||
} else {
|
} else {
|
||||||
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info);
|
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info);
|
||||||
|
@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.inventory.CraftingInventory;
|
import org.bukkit.inventory.CraftingInventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.ViaListener;
|
import us.myles.ViaVersion.api.ViaListener;
|
||||||
@ -33,7 +34,11 @@ public class ArmorListener extends ViaListener {
|
|||||||
// Ensure that the player is on our pipe
|
// Ensure that the player is on our pipe
|
||||||
if (!isOnPipe(player)) return;
|
if (!isOnPipe(player)) return;
|
||||||
|
|
||||||
int armor = ArmorType.calculateArmorPoints(player.getInventory().getArmorContents());
|
|
||||||
|
int armor = 0;
|
||||||
|
for (ItemStack stack : player.getInventory().getArmorContents()) {
|
||||||
|
armor += ArmorType.findById(stack.getTypeId()).getArmorPoints();
|
||||||
|
}
|
||||||
|
|
||||||
PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player));
|
PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player));
|
||||||
try {
|
try {
|
||||||
@ -58,7 +63,7 @@ public class ArmorListener extends ViaListener {
|
|||||||
if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
|
if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
|
||||||
final Player player = (Player) human;
|
final Player player = (Player) human;
|
||||||
if (e.getCurrentItem() != null) {
|
if (e.getCurrentItem() != null) {
|
||||||
if (ArmorType.isArmor(e.getCurrentItem().getType())) {
|
if (ArmorType.isArmor(e.getCurrentItem().getTypeId())) {
|
||||||
sendDelayedArmorUpdate(player);
|
sendDelayedArmorUpdate(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.platform.ViaInjector;
|
|||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
|
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.update.UpdateUtil;
|
import us.myles.ViaVersion.update.UpdateUtil;
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ public class ViaManager {
|
|||||||
private boolean debug = false;
|
private boolean debug = false;
|
||||||
// Internals
|
// Internals
|
||||||
private ViaInjector injector;
|
private ViaInjector injector;
|
||||||
private ViaVersionCommand commandHandler;
|
private ViaCommandHandler commandHandler;
|
||||||
|
|
||||||
public ViaManager(ViaPlatform platform) {
|
public ViaManager(ViaPlatform platform) {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
|
@ -217,4 +217,9 @@ public interface ViaVersionConfig {
|
|||||||
* @return Disconnect message
|
* @return Disconnect message
|
||||||
*/
|
*/
|
||||||
String getReloadDisconnectMsg();
|
String getReloadDisconnectMsg();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads the config from disk
|
||||||
|
*/
|
||||||
|
void reloadConfig();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
package us.myles.ViaVersion.api.command;
|
package us.myles.ViaVersion.api.command;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface ViaCommandSender {
|
public interface ViaCommandSender {
|
||||||
public boolean hasPermission(String permission);
|
public boolean hasPermission(String permission);
|
||||||
|
|
||||||
public void sendMessage(String msg);
|
public void sendMessage(String msg);
|
||||||
|
|
||||||
|
public UUID getUUID();
|
||||||
|
|
||||||
|
public String getName();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package us.myles.ViaVersion.api.platform;
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.ViaAPI;
|
import us.myles.ViaVersion.api.ViaAPI;
|
||||||
import us.myles.ViaVersion.api.ViaVersionConfig;
|
import us.myles.ViaVersion.api.ViaVersionConfig;
|
||||||
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -22,6 +23,8 @@ public interface ViaPlatform<T> {
|
|||||||
|
|
||||||
public void runSync(Runnable runnable);
|
public void runSync(Runnable runnable);
|
||||||
|
|
||||||
|
public ViaCommandSender[] getOnlinePlayers();
|
||||||
|
|
||||||
public void sendMessage(UUID uuid, String message);
|
public void sendMessage(UUID uuid, String message);
|
||||||
|
|
||||||
public boolean kickPlayer(UUID uuid, String message);
|
public boolean kickPlayer(UUID uuid, String message);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package us.myles.ViaVersion.commands.defaultsubs;
|
package us.myles.ViaVersion.commands.defaultsubs;
|
||||||
|
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
@ -20,7 +21,7 @@ public class AutoTeamSubCmd extends ViaSubCommand {
|
|||||||
public boolean execute(ViaCommandSender sender, String[] args) {
|
public boolean execute(ViaCommandSender sender, String[] args) {
|
||||||
ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
||||||
|
|
||||||
boolean newValue = !ViaVersion.getConfig().isAutoTeam();
|
boolean newValue = !Via.getConfig().isAutoTeam();
|
||||||
plugin.getConfig().set("auto-team", newValue);
|
plugin.getConfig().set("auto-team", newValue);
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
sendMessage(sender, "&6We will %s", (newValue ? "&aautomatically team players" : "&cno longer auto team players"));
|
sendMessage(sender, "&6We will %s", (newValue ? "&aautomatically team players" : "&cno longer auto team players"));
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package us.myles.ViaVersion.commands.defaultsubs;
|
package us.myles.ViaVersion.commands.defaultsubs;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
|
|
||||||
@ -19,10 +17,8 @@ public class DebugSubCmd extends ViaSubCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(ViaCommandSender sender, String[] args) {
|
public boolean execute(ViaCommandSender sender, String[] args) {
|
||||||
ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
Via.getManager().setDebug(!Via.getManager().isDebug());
|
||||||
|
sendMessage(sender, "&6Debug mode is now %s", (Via.getManager().isDebug() ? "&aenabled" : "&cdisabled"));
|
||||||
plugin.setDebug(!plugin.isDebug());
|
|
||||||
sendMessage(sender, "&6Debug mode is now %s", (plugin.isDebug() ? "&aenabled" : "&cdisabled"));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.commands.defaultsubs;
|
package us.myles.ViaVersion.commands.defaultsubs;
|
||||||
|
|
||||||
import io.netty.util.ResourceLeakDetector;
|
import io.netty.util.ResourceLeakDetector;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
|
|
||||||
|
@ -3,12 +3,6 @@ package us.myles.ViaVersion.commands.defaultsubs;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package us.myles.ViaVersion.commands.defaultsubs;
|
package us.myles.ViaVersion.commands.defaultsubs;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
|
||||||
|
|
||||||
public class HelpSubCmd extends ViaSubCommand {
|
public class HelpSubCmd extends ViaSubCommand {
|
||||||
@Override
|
@Override
|
||||||
@ -20,9 +17,7 @@ public class HelpSubCmd extends ViaSubCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(ViaCommandSender sender, String[] args) {
|
public boolean execute(ViaCommandSender sender, String[] args) {
|
||||||
ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
Via.getManager().getCommandHandler().showHelp(sender);
|
||||||
|
|
||||||
((ViaCommandHandler) plugin.getCommandHandler()).showHelp(sender);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package us.myles.ViaVersion.commands.defaultsubs;
|
package us.myles.ViaVersion.commands.defaultsubs;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
@ -35,8 +32,8 @@ public class ListSubCmd extends ViaSubCommand {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
|
||||||
int playerVersion = ViaVersion.getInstance().getPlayerVersion(p);
|
int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
|
||||||
ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion);
|
ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion);
|
||||||
if (!playerVersions.containsKey(key))
|
if (!playerVersions.containsKey(key))
|
||||||
playerVersions.put(key, new HashSet<String>());
|
playerVersions.put(key, new HashSet<String>());
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package us.myles.ViaVersion.commands.defaultsubs;
|
package us.myles.ViaVersion.commands.defaultsubs;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
@ -35,13 +31,13 @@ public class PPSSubCmd extends ViaSubCommand {
|
|||||||
int clients = 0;
|
int clients = 0;
|
||||||
long max = 0;
|
long max = 0;
|
||||||
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
|
||||||
if (!ViaVersion.getInstance().isPorted(p))
|
if (!Via.getAPI().isPorted(p.getUUID()))
|
||||||
continue;
|
continue;
|
||||||
int playerVersion = ViaVersion.getInstance().getPlayerVersion(p);
|
int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
|
||||||
if (!playerVersions.containsKey(playerVersion))
|
if (!playerVersions.containsKey(playerVersion))
|
||||||
playerVersions.put(playerVersion, new HashSet<String>());
|
playerVersions.put(playerVersion, new HashSet<String>());
|
||||||
UserConnection uc = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(p);
|
UserConnection uc = Via.getManager().getConnection(p.getUUID());
|
||||||
if (uc.getPacketsPerSecond() > -1) {
|
if (uc.getPacketsPerSecond() > -1) {
|
||||||
playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketsPerSecond() + " PPS)");
|
playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketsPerSecond() + " PPS)");
|
||||||
totalPackets += uc.getPacketsPerSecond();
|
totalPackets += uc.getPacketsPerSecond();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.commands.defaultsubs;
|
package us.myles.ViaVersion.commands.defaultsubs;
|
||||||
|
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
|
|
||||||
@ -18,9 +17,7 @@ public class ReloadSubCmd extends ViaSubCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(ViaCommandSender sender, String[] args) {
|
public boolean execute(ViaCommandSender sender, String[] args) {
|
||||||
ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
Via.getConfig().reloadConfig();
|
||||||
|
|
||||||
plugin.getConf().generateConfig();
|
|
||||||
sendMessage(sender, "&6Configuration successfully reloaded! Some features may need a restart.");
|
sendMessage(sender, "&6Configuration successfully reloaded! Some features may need a restart.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -11,54 +9,39 @@ import java.util.HashMap;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum ArmorType {
|
public enum ArmorType {
|
||||||
|
|
||||||
LEATHER_HELMET(1, 298, Material.LEATHER_HELMET),
|
LEATHER_HELMET(1, 298),
|
||||||
LEATHER_CHESTPLATE(3, 299, Material.LEATHER_CHESTPLATE),
|
LEATHER_CHESTPLATE(3, 299),
|
||||||
LEATHER_LEGGINGS(2, 300, Material.LEATHER_LEGGINGS),
|
LEATHER_LEGGINGS(2, 300),
|
||||||
LEATHER_BOOTS(1, 301, Material.LEATHER_BOOTS),
|
LEATHER_BOOTS(1, 301),
|
||||||
CHAINMAIL_HELMET(2, 302, Material.CHAINMAIL_HELMET),
|
CHAINMAIL_HELMET(2, 302),
|
||||||
CHAINMAIL_CHESTPLATE(5, 303, Material.CHAINMAIL_CHESTPLATE),
|
CHAINMAIL_CHESTPLATE(5, 303),
|
||||||
CHAINMAIL_LEGGINGS(4, 304, Material.CHAINMAIL_LEGGINGS),
|
CHAINMAIL_LEGGINGS(4, 304),
|
||||||
CHAINMAIL_BOOTS(1, 305, Material.CHAINMAIL_BOOTS),
|
CHAINMAIL_BOOTS(1, 305),
|
||||||
IRON_HELMET(2, 306, Material.IRON_HELMET),
|
IRON_HELMET(2, 306),
|
||||||
IRON_CHESTPLATE(6, 307, Material.IRON_CHESTPLATE),
|
IRON_CHESTPLATE(6, 307),
|
||||||
IRON_LEGGINGS(5, 308, Material.IRON_LEGGINGS),
|
IRON_LEGGINGS(5, 308),
|
||||||
IRON_BOOTS(2, 309, Material.IRON_BOOTS),
|
IRON_BOOTS(2, 309),
|
||||||
DIAMOND_HELMET(3, 310, Material.DIAMOND_HELMET),
|
DIAMOND_HELMET(3, 310),
|
||||||
DIAMOND_CHESTPLATE(8, 311, Material.DIAMOND_CHESTPLATE),
|
DIAMOND_CHESTPLATE(8, 311),
|
||||||
DIAMOND_LEGGINGS(6, 312, Material.DIAMOND_LEGGINGS),
|
DIAMOND_LEGGINGS(6, 312),
|
||||||
DIAMOND_BOOTS(3, 313, Material.DIAMOND_BOOTS),
|
DIAMOND_BOOTS(3, 313),
|
||||||
GOLD_HELMET(2, 314, Material.GOLD_HELMET),
|
GOLD_HELMET(2, 314),
|
||||||
GOLD_CHESTPLATE(5, 315, Material.GOLD_CHESTPLATE),
|
GOLD_CHESTPLATE(5, 315),
|
||||||
GOLD_LEGGINGS(3, 316, Material.GOLD_LEGGINGS),
|
GOLD_LEGGINGS(3, 316),
|
||||||
GOLD_BOOTS(1, 317, Material.GOLD_BOOTS),
|
GOLD_BOOTS(1, 317),
|
||||||
NONE(0, 0, Material.AIR);
|
NONE(0, 0);
|
||||||
|
|
||||||
private static HashMap<Material, ArmorType> armor;
|
private static HashMap<Integer, ArmorType> armor;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
armor = new HashMap<Material, ArmorType>();
|
armor = new HashMap<>();
|
||||||
for (ArmorType a : ArmorType.values()) {
|
for (ArmorType a : ArmorType.values()) {
|
||||||
armor.put(a.getType(), a);
|
armor.put(a.getId(), a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int armorPoints;
|
private final int armorPoints;
|
||||||
private final int id;
|
private final int id;
|
||||||
private final Material type;
|
|
||||||
|
|
||||||
public static ArmorType findByType(Material type) {
|
|
||||||
ArmorType t = armor.get(type);
|
|
||||||
return t == null ? ArmorType.NONE : t;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int calculateArmorPoints(ItemStack[] armor) {
|
|
||||||
int total = 0;
|
|
||||||
for (ItemStack anArmor : armor) {
|
|
||||||
if (anArmor != null)
|
|
||||||
total += findByType(anArmor.getType()).getArmorPoints();
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArmorType findById(int id) {
|
public static ArmorType findById(int id) {
|
||||||
for (ArmorType a : ArmorType.values())
|
for (ArmorType a : ArmorType.values())
|
||||||
@ -67,9 +50,9 @@ public enum ArmorType {
|
|||||||
return ArmorType.NONE;
|
return ArmorType.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isArmor(Material material) {
|
public static boolean isArmor(int id) {
|
||||||
for (ArmorType a : ArmorType.values())
|
for (ArmorType a : ArmorType.values())
|
||||||
if (a.getType() == material)
|
if (a.getId() == id)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -83,8 +66,7 @@ public enum ArmorType {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getType() {
|
public int getId() {
|
||||||
return this.type;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren