refactor: move enums into own file

This commit is contained in:
Simon Giesel 2020-05-27 11:39:38 +02:00
parent eb9bfc78d1
commit 817a437b5d
6 changed files with 32 additions and 18 deletions

View file

@ -0,0 +1,5 @@
package de.cliffbreak.varo.enums;
public enum PlayerCacheType {
NAME, SKINPARTS, MAINHAND, WORLD, X, Y, Z, YAW, PITCH,
}

View file

@ -0,0 +1,5 @@
package de.cliffbreak.varo.enums;
public enum PlayerInteractType {
ATTACK, INTERACT,
}

View file

@ -4,15 +4,17 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import de.cliffbreak.varo.enums.PlayerInteractType;
public class PlayerInteractNPCEvent extends Event { public class PlayerInteractNPCEvent extends Event {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final Type type; private final PlayerInteractType type;
private final Player damager; private final Player damager;
private final int id; private final int id;
private final double damage; private final double damage;
private final boolean isCritical; private final boolean isCritical;
public PlayerInteractNPCEvent(Type type, Player damager, int id, double damage, boolean isCritical) { public PlayerInteractNPCEvent(PlayerInteractType type, Player damager, int id, double damage, boolean isCritical) {
super(true); super(true);
this.type = type; this.type = type;
this.damager = damager; this.damager = damager;
@ -22,9 +24,9 @@ public class PlayerInteractNPCEvent extends Event {
} }
/** /**
* @return InteractionType of the Event * @return PlayerInteractType of the Event
*/ */
public Type getType() { public PlayerInteractType getType() {
return type; return type;
} }
@ -64,8 +66,4 @@ public class PlayerInteractNPCEvent extends Event {
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
public enum Type {
ATTACK, INTERACT,
}
} }

View file

@ -6,7 +6,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import de.cliffbreak.varo.Varo; import de.cliffbreak.varo.Varo;
import de.cliffbreak.varo.utils.PlayerCache.PlayerCacheType; import de.cliffbreak.varo.enums.PlayerCacheType;
public class PlayerClientOptionsChangeListener implements Listener { public class PlayerClientOptionsChangeListener implements Listener {

View file

@ -4,8 +4,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import de.cliffbreak.varo.Varo; import de.cliffbreak.varo.Varo;
import de.cliffbreak.varo.enums.PlayerInteractType;
import de.cliffbreak.varo.events.PlayerInteractNPCEvent; import de.cliffbreak.varo.events.PlayerInteractNPCEvent;
import de.cliffbreak.varo.events.PlayerInteractNPCEvent.Type;
public class PlayerInteractNPCListener implements Listener { public class PlayerInteractNPCListener implements Listener {
@ -17,7 +17,7 @@ public class PlayerInteractNPCListener implements Listener {
@EventHandler @EventHandler
public void onEntityDamageByEntity(final PlayerInteractNPCEvent e) { public void onEntityDamageByEntity(final PlayerInteractNPCEvent e) {
if (e.getType().equals(Type.ATTACK)) { if (e.getType().equals(PlayerInteractType.ATTACK)) {
this.plugin.getNPCManager().addDamage(e.getDamager(), e.getId(), e.getDamage(), e.getIsCritical()); this.plugin.getNPCManager().addDamage(e.getDamager(), e.getId(), e.getDamage(), e.getIsCritical());
} }
} }

View file

@ -8,6 +8,7 @@ import org.bukkit.inventory.MainHand;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import de.cliffbreak.varo.Varo; import de.cliffbreak.varo.Varo;
import de.cliffbreak.varo.enums.PlayerCacheType;
public class PlayerCache { public class PlayerCache {
@ -64,12 +65,21 @@ public class PlayerCache {
} }
public int getSkinParts(final String uuid) { public int getSkinParts(final String uuid) {
return (int) this.plugin.getDatabase().getPlayerCache(uuid, PlayerCacheType.SKINPARTS.toString().toLowerCase()); Object skinParts = this.plugin.getDatabase().getPlayerCache(uuid,
PlayerCacheType.SKINPARTS.toString().toLowerCase());
if (skinParts == null) {
return 127;
}
return (int) skinParts;
} }
public MainHand getMainHand(final String uuid) { public MainHand getMainHand(final String uuid) {
return MainHand.valueOf((String) this.plugin.getDatabase().getPlayerCache(uuid, String mainHand = (String) this.plugin.getDatabase().getPlayerCache(uuid,
PlayerCacheType.MAINHAND.toString().toLowerCase())); PlayerCacheType.MAINHAND.toString().toLowerCase());
if (mainHand == null) {
return MainHand.RIGHT;
}
return MainHand.valueOf(mainHand);
} }
public byte getMainHandAsByte(final String uuid) { public byte getMainHandAsByte(final String uuid) {
@ -78,8 +88,4 @@ public class PlayerCache {
else else
return (byte) 0; return (byte) 0;
} }
public enum PlayerCacheType {
NAME, SKINPARTS, MAINHAND, WORLD, X, Y, Z, YAW, PITCH,
}
} }