Update all legacy IDs

This commit is contained in:
dordsor21 2018-12-20 00:43:47 +00:00
parent adc2d980f4
commit ee6d52efa3
3 changed files with 214 additions and 137 deletions

View File

@ -25,7 +25,7 @@ import org.bukkit.plugin.Plugin;
import java.util.List; import java.util.List;
public class EntitySpawnListener implements Listener { @SuppressWarnings("unused") public class EntitySpawnListener implements Listener {
private static boolean ignoreTP = false; private static boolean ignoreTP = false;

View File

@ -20,6 +20,8 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Piston;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -74,8 +76,7 @@ import java.util.regex.Pattern;
} }
} }
public static void sendBlockChange(final org.bukkit.Location bloc, final Material type, public static void sendBlockChange(final org.bukkit.Location bloc, final BlockData data) {
final byte data) {
TaskManager.runTaskLater(() -> { TaskManager.runTaskLater(() -> {
String world = bloc.getWorld().getName(); String world = bloc.getWorld().getName();
int x = bloc.getBlockX(); int x = bloc.getBlockX();
@ -89,7 +90,7 @@ import java.util.regex.Pattern;
|| 16 * Math.abs(loc.getZ() - z) / 16 > distance) { || 16 * Math.abs(loc.getZ() - z) / 16 > distance) {
continue; continue;
} }
((BukkitPlayer) player).player.sendBlockChange(bloc, type, data); ((BukkitPlayer) player).player.sendBlockChange(bloc, data);
} }
} }
}, 3); }, 3);
@ -230,32 +231,48 @@ import java.util.regex.Pattern;
Block block = event.getBlock(); Block block = event.getBlock();
switch (block.getType()) { switch (block.getType()) {
case OBSERVER: case OBSERVER:
case LEGACY_REDSTONE_LAMP_OFF: case REDSTONE:
case REDSTONE_ORE:
case REDSTONE_BLOCK:
case REDSTONE_TORCH:
case REDSTONE_WALL_TORCH:
case REDSTONE_WIRE: case REDSTONE_WIRE:
case LEGACY_REDSTONE_LAMP_ON: case REDSTONE_LAMP:
case LEGACY_PISTON_BASE: case PISTON_HEAD:
case LEGACY_PISTON_STICKY_BASE: case PISTON:
case LEGACY_IRON_DOOR_BLOCK: case STICKY_PISTON:
case MOVING_PISTON:
case LEVER: case LEVER:
case LEGACY_WOODEN_DOOR: case ACACIA_BUTTON:
case LEGACY_FENCE_GATE: case BIRCH_BUTTON:
case LEGACY_WOOD_BUTTON: case DARK_OAK_BUTTON:
case JUNGLE_BUTTON:
case OAK_BUTTON:
case SPRUCE_BUTTON:
case STONE_BUTTON: case STONE_BUTTON:
case LEGACY_IRON_PLATE: case STONE_PRESSURE_PLATE:
case LEGACY_WOOD_PLATE: case ACACIA_PRESSURE_PLATE:
case LEGACY_STONE_PLATE: case BIRCH_PRESSURE_PLATE:
case LEGACY_GOLD_PLATE: case DARK_OAK_PRESSURE_PLATE:
case HEAVY_WEIGHTED_PRESSURE_PLATE:
case JUNGLE_PRESSURE_PLATE:
case LIGHT_WEIGHTED_PRESSURE_PLATE:
case OAK_PRESSURE_PLATE:
case SPRUCE_PRESSURE_PLATE:
case SPRUCE_DOOR: case SPRUCE_DOOR:
case BIRCH_DOOR: case BIRCH_DOOR:
case JUNGLE_DOOR: case JUNGLE_DOOR:
case ACACIA_DOOR: case ACACIA_DOOR:
case DARK_OAK_DOOR: case DARK_OAK_DOOR:
case IRON_DOOR:
case OAK_DOOR:
case IRON_TRAPDOOR: case IRON_TRAPDOOR:
case SPRUCE_FENCE_GATE: case SPRUCE_FENCE_GATE:
case BIRCH_FENCE_GATE: case BIRCH_FENCE_GATE:
case JUNGLE_FENCE_GATE: case JUNGLE_FENCE_GATE:
case ACACIA_FENCE_GATE: case ACACIA_FENCE_GATE:
case DARK_OAK_FENCE_GATE: case DARK_OAK_FENCE_GATE:
case OAK_FENCE_GATE:
case POWERED_RAIL: case POWERED_RAIL:
return; return;
default: default:
@ -283,7 +300,7 @@ import java.util.regex.Pattern;
} }
} }
} else { } else {
disable = UUIDHandler.getPlayer(plot.owner) == null; disable = UUIDHandler.getPlayer(plot.guessOwner()) == null;
} }
if (disable) { if (disable) {
for (UUID trusted : plot.getTrusted()) { for (UUID trusted : plot.getTrusted()) {
@ -312,8 +329,7 @@ import java.util.regex.Pattern;
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPhysicsEvent(BlockPhysicsEvent event) { public void onPhysicsEvent(BlockPhysicsEvent event) {
switch (event.getChangedType()) { switch (event.getChangedType()) {
case LEGACY_REDSTONE_COMPARATOR_OFF: case COMPARATOR: {
case LEGACY_REDSTONE_COMPARATOR_ON: {
Block block = event.getBlock(); Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation()); Location loc = BukkitUtil.getLocation(block.getLocation());
PlotArea area = loc.getPlotArea(); PlotArea area = loc.getPlotArea();
@ -352,8 +368,9 @@ import java.util.regex.Pattern;
if (Settings.Redstone.DETECT_INVALID_EDGE_PISTONS) { if (Settings.Redstone.DETECT_INVALID_EDGE_PISTONS) {
Block block = event.getBlock(); Block block = event.getBlock();
switch (block.getType()) { switch (block.getType()) {
case LEGACY_PISTON_BASE: case PISTON:
case LEGACY_PISTON_STICKY_BASE: case STICKY_PISTON:
Piston piston = (Piston) block.getBlockData();
Location loc = BukkitUtil.getLocation(block.getLocation()); Location loc = BukkitUtil.getLocation(block.getLocation());
PlotArea area = loc.getPlotArea(); PlotArea area = loc.getPlotArea();
if (area == null) { if (area == null) {
@ -363,22 +380,17 @@ import java.util.regex.Pattern;
if (plot == null) { if (plot == null) {
return; return;
} }
int data = block.getData(); switch (piston.getFacing()) {
switch (data) { case EAST:
case 5:
case 13:
loc.setX(loc.getX() + 1); loc.setX(loc.getX() + 1);
break; break;
case 4: case SOUTH:
case 12:
loc.setX(loc.getX() - 1); loc.setX(loc.getX() - 1);
break; break;
case 3: case WEST:
case 11:
loc.setZ(loc.getZ() + 1); loc.setZ(loc.getZ() + 1);
break; break;
case 2: case NORTH:
case 10:
loc.setZ(loc.getZ() - 1); loc.setZ(loc.getZ() - 1);
break; break;
} }
@ -632,7 +644,7 @@ import java.util.regex.Pattern;
// Check allowed // Check allowed
Entity passenger = vehicle.getPassenger(); Entity passenger = vehicle.getPassengers().get(1);
if (passenger instanceof Player) { if (passenger instanceof Player) {
final Player player = (Player) passenger; final Player player = (Player) passenger;
@ -1114,7 +1126,7 @@ import java.util.regex.Pattern;
event.setCancelled(true); event.setCancelled(true);
} }
break; break;
case LEGACY_MYCEL: case MYCELIUM:
if (Flags.MYCEL_GROW.isFalse(plot)) { if (Flags.MYCEL_GROW.isFalse(plot)) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -1238,7 +1250,7 @@ import java.util.regex.Pattern;
event.setCancelled(true); event.setCancelled(true);
} }
break; break;
case LEGACY_SOIL: case FARMLAND:
if (Flags.SOIL_DRY.isFalse(plot)) { if (Flags.SOIL_DRY.isFalse(plot)) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -1274,7 +1286,7 @@ import java.util.regex.Pattern;
} }
} }
} else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
.equals(plot, area.getOwnedPlot(fLocation))) { .equals(null, area.getOwnedPlot(fLocation))) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -1350,7 +1362,7 @@ import java.util.regex.Pattern;
this.pistonBlocks = false; this.pistonBlocks = false;
} }
} }
if (!this.pistonBlocks && block.getType() != Material.LEGACY_PISTON_BASE) { if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
BlockFace dir = event.getDirection(); BlockFace dir = event.getDirection();
location = BukkitUtil.getLocation(block.getLocation() location = BukkitUtil.getLocation(block.getLocation()
.add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); .add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
@ -1391,7 +1403,7 @@ import java.util.regex.Pattern;
this.pistonBlocks = false; this.pistonBlocks = false;
} }
} }
if (!this.pistonBlocks && block.getType() != Material.LEGACY_PISTON_BASE) { if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
location = BukkitUtil.getLocation( location = BukkitUtil.getLocation(
block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
if (!area.contains(location)) { if (!area.contains(location)) {
@ -1541,9 +1553,7 @@ import java.util.regex.Pattern;
return; return;
} }
} }
Block block = player.getTargetBlock(null, 7);
HashSet<Material> blocks = null;
Block block = player.getTargetBlock(blocks, 7);
BlockState state = block.getState(); BlockState state = block.getState();
if (state == null) { if (state == null) {
return; return;
@ -1705,7 +1715,8 @@ import java.util.regex.Pattern;
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
location = BukkitUtil.getLocation(block.getLocation()); location = BukkitUtil.getLocation(block.getLocation());
Material blockType = block.getType(); Material blockType = block.getType();
int blockId = blockType.getId(); int blockId = ((LegacyPlotBlock) PlotSquared.get().IMP.getLegacyMappings()
.fromStringToLegacy(blockType.name())).id;
switch (blockType) { switch (blockType) {
case ANVIL: case ANVIL:
case ACACIA_DOOR: case ACACIA_DOOR:
@ -1714,38 +1725,89 @@ import java.util.regex.Pattern;
case IRON_DOOR: case IRON_DOOR:
case JUNGLE_DOOR: case JUNGLE_DOOR:
case SPRUCE_DOOR: case SPRUCE_DOOR:
case LEGACY_TRAP_DOOR: case OAK_DOOR:
case ACACIA_TRAPDOOR:
case BIRCH_TRAPDOOR:
case DARK_OAK_TRAPDOOR:
case JUNGLE_TRAPDOOR:
case OAK_TRAPDOOR:
case SPRUCE_TRAPDOOR:
case IRON_TRAPDOOR: case IRON_TRAPDOOR:
case LEGACY_WOOD_DOOR:
case LEGACY_WOODEN_DOOR:
case TRAPPED_CHEST: case TRAPPED_CHEST:
case ENDER_CHEST: case ENDER_CHEST:
case CHEST: case CHEST:
case ACACIA_FENCE_GATE: case ACACIA_FENCE_GATE:
case BIRCH_FENCE_GATE: case BIRCH_FENCE_GATE:
case DARK_OAK_FENCE_GATE: case DARK_OAK_FENCE_GATE:
case LEGACY_FENCE_GATE: case OAK_FENCE_GATE:
case JUNGLE_FENCE_GATE: case JUNGLE_FENCE_GATE:
case SPRUCE_FENCE_GATE: case SPRUCE_FENCE_GATE:
case LEVER: case LEVER:
case LEGACY_DIODE: case REDSTONE_TORCH:
case LEGACY_DIODE_BLOCK_OFF: case REDSTONE_WALL_TORCH:
case LEGACY_DIODE_BLOCK_ON:
case COMMAND_BLOCK: case COMMAND_BLOCK:
case LEGACY_REDSTONE_COMPARATOR: case COMPARATOR:
case LEGACY_REDSTONE_COMPARATOR_OFF:
case LEGACY_REDSTONE_COMPARATOR_ON:
case REDSTONE_ORE: case REDSTONE_ORE:
case LEGACY_WOOD_BUTTON: case BIRCH_BUTTON:
case DARK_OAK_BUTTON:
case JUNGLE_BUTTON:
case ACACIA_BUTTON:
case OAK_BUTTON:
case SPRUCE_BUTTON:
case STONE_BUTTON: case STONE_BUTTON:
case BEACON: case BEACON:
case LEGACY_BED_BLOCK: case BLACK_BED:
case BLUE_BED:
case BROWN_BED:
case CYAN_BED:
case GRAY_BED:
case GREEN_BED:
case LIGHT_BLUE_BED:
case LIGHT_GRAY_BED:
case LIME_BED:
case MAGENTA_BED:
case ORANGE_BED:
case PINK_BED:
case PURPLE_BED:
case RED_BED:
case WHITE_BED:
case YELLOW_BED:
case SIGN: case SIGN:
case WALL_SIGN: case WALL_SIGN:
case LEGACY_ENCHANTMENT_TABLE: case ENCHANTING_TABLE:
case BREWING_STAND: case BREWING_STAND:
case LEGACY_STANDING_BANNER: case BLACK_BANNER:
case LEGACY_BURNING_FURNACE: case BLACK_WALL_BANNER:
case BLUE_BANNER:
case BLUE_WALL_BANNER:
case BROWN_BANNER:
case BROWN_WALL_BANNER:
case CYAN_BANNER:
case CYAN_WALL_BANNER:
case GRAY_BANNER:
case GRAY_WALL_BANNER:
case GREEN_BANNER:
case GREEN_WALL_BANNER:
case LIGHT_BLUE_BANNER:
case LIGHT_BLUE_WALL_BANNER:
case LIGHT_GRAY_BANNER:
case LIGHT_GRAY_WALL_BANNER:
case LIME_BANNER:
case LIME_WALL_BANNER:
case MAGENTA_BANNER:
case MAGENTA_WALL_BANNER:
case ORANGE_BANNER:
case ORANGE_WALL_BANNER:
case PINK_BANNER:
case PINK_WALL_BANNER:
case PURPLE_BANNER:
case PURPLE_WALL_BANNER:
case RED_BANNER:
case RED_WALL_BANNER:
case WHITE_BANNER:
case WHITE_WALL_BANNER:
case YELLOW_BANNER:
case YELLOW_WALL_BANNER:
case FURNACE: case FURNACE:
case CAKE: case CAKE:
case DISPENSER: case DISPENSER:
@ -1754,7 +1816,7 @@ import java.util.regex.Pattern;
case NOTE_BLOCK: case NOTE_BLOCK:
case JUKEBOX: case JUKEBOX:
case CRAFTING_TABLE: case CRAFTING_TABLE:
case LEGACY_SILVER_SHULKER_BOX: case LIGHT_GRAY_SHULKER_BOX:
case BLACK_SHULKER_BOX: case BLACK_SHULKER_BOX:
case BLUE_SHULKER_BOX: case BLUE_SHULKER_BOX:
case RED_SHULKER_BOX: case RED_SHULKER_BOX:
@ -1770,8 +1832,8 @@ import java.util.regex.Pattern;
case LIME_SHULKER_BOX: case LIME_SHULKER_BOX:
case LIGHT_BLUE_SHULKER_BOX: case LIGHT_BLUE_SHULKER_BOX:
case MAGENTA_SHULKER_BOX: case MAGENTA_SHULKER_BOX:
case LEGACY_COMMAND_REPEATING: case CHAIN_COMMAND_BLOCK:
case LEGACY_COMMAND_CHAIN: case REPEATING_COMMAND_BLOCK:
eventType = PlayerBlockEventType.INTERACT_BLOCK; eventType = PlayerBlockEventType.INTERACT_BLOCK;
break; break;
@ -1785,18 +1847,17 @@ import java.util.regex.Pattern;
break; break;
} }
lb = new BukkitLazyBlock(PlotBlock.get(block.getType().toString())); lb = new BukkitLazyBlock(PlotBlock.get(block.getType().toString()));
ItemStack hand = player.getItemInHand(); ItemStack hand = player.getInventory().getItemInMainHand();
if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK
|| !player.isSneaking())) { || !player.isSneaking())) {
break; break;
} }
Material type = (hand == null) ? null : hand.getType(); Material type = (hand == null) ? null : hand.getType();
int id = (type == null) ? 0 : type.getId();
if (type == Material.AIR) { if (type == Material.AIR) {
eventType = PlayerBlockEventType.INTERACT_BLOCK; eventType = PlayerBlockEventType.INTERACT_BLOCK;
break; break;
} }
if (id < 198) { if (type == null || type.isBlock()) {
location = BukkitUtil location = BukkitUtil
.getLocation(block.getRelative(event.getBlockFace()).getLocation()); .getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_BLOCK; eventType = PlayerBlockEventType.PLACE_BLOCK;
@ -1804,63 +1865,81 @@ import java.util.regex.Pattern;
} }
Material handType = hand.getType(); Material handType = hand.getType();
lb = new BukkitLazyBlock(PlotBlock.get(handType.toString())); lb = new BukkitLazyBlock(PlotBlock.get(handType.toString()));
switch (handType) { if (handType.toString().endsWith("egg")) {
case LEGACY_FIREWORK: eventType = PlayerBlockEventType.SPAWN_MOB;
case LEGACY_MONSTER_EGG: } else {
case LEGACY_MONSTER_EGGS: switch (handType) {
eventType = PlayerBlockEventType.SPAWN_MOB; case FIREWORK_ROCKET:
break; case FIREWORK_STAR:
case ARMOR_STAND: eventType = PlayerBlockEventType.SPAWN_MOB;
location = BukkitUtil break;
.getLocation(block.getRelative(event.getBlockFace()).getLocation()); case ARMOR_STAND:
eventType = PlayerBlockEventType.PLACE_MISC; location = BukkitUtil
break; .getLocation(block.getRelative(event.getBlockFace()).getLocation());
case WRITTEN_BOOK: eventType = PlayerBlockEventType.PLACE_MISC;
case LEGACY_BOOK_AND_QUILL: break;
case BOOK: case WRITTEN_BOOK:
eventType = PlayerBlockEventType.READ; case WRITABLE_BOOK:
break; case ENCHANTED_BOOK:
case APPLE: case KNOWLEDGE_BOOK:
case BAKED_POTATO: case BOOK:
case LEGACY_MUSHROOM_SOUP: eventType = PlayerBlockEventType.READ;
case BREAD: break;
case CARROT: case APPLE:
case LEGACY_CARROT_ITEM: case BAKED_POTATO:
case COOKIE: case MUSHROOM_STEW:
case LEGACY_GRILLED_PORK: case BREAD:
case POISONOUS_POTATO: case CARROT:
case MUTTON: case GOLDEN_CARROT:
case LEGACY_PORK: case COOKIE:
case POTATO: case PORKCHOP:
case LEGACY_POTATO_ITEM: case POISONOUS_POTATO:
case POTION: case MUTTON:
case PUMPKIN_PIE: case COOKED_PORKCHOP:
case RABBIT: case POTATO:
case RABBIT_FOOT: case POTION:
case RABBIT_STEW: case PUMPKIN_PIE:
case LEGACY_RAW_BEEF: case RABBIT:
case LEGACY_RAW_FISH: case RABBIT_FOOT:
case LEGACY_RAW_CHICKEN: case RABBIT_STEW:
eventType = PlayerBlockEventType.EAT; case BEEF:
break; case COOKED_BEEF:
case MINECART: case TROPICAL_FISH:
case LEGACY_STORAGE_MINECART: case PUFFERFISH:
case LEGACY_POWERED_MINECART: case CHICKEN:
case HOPPER_MINECART: case COOKED_CHICKEN:
case LEGACY_EXPLOSIVE_MINECART: case COOKED_MUTTON:
case LEGACY_COMMAND_MINECART: case COOKED_RABBIT:
case LEGACY_BOAT: case COOKED_SALMON:
eventType = PlayerBlockEventType.PLACE_VEHICLE; case SALMON:
break; case COD:
case PAINTING: case COOKED_COD:
case ITEM_FRAME: eventType = PlayerBlockEventType.EAT;
location = BukkitUtil break;
.getLocation(block.getRelative(event.getBlockFace()).getLocation()); case MINECART:
eventType = PlayerBlockEventType.PLACE_HANGING; case CHEST_MINECART:
break; case FURNACE_MINECART:
default: case HOPPER_MINECART:
eventType = PlayerBlockEventType.INTERACT_BLOCK; case TNT_MINECART:
break; case COMMAND_BLOCK_MINECART:
case BIRCH_BOAT:
case ACACIA_BOAT:
case DARK_OAK_BOAT:
case JUNGLE_BOAT:
case OAK_BOAT:
case SPRUCE_BOAT:
eventType = PlayerBlockEventType.PLACE_VEHICLE;
break;
case PAINTING:
case ITEM_FRAME:
location = BukkitUtil
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_HANGING;
break;
default:
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break;
}
} }
break; break;
} }
@ -1912,7 +1991,7 @@ import java.util.regex.Pattern;
case BUILD_WITHER: case BUILD_WITHER:
case BUILD_SNOWMAN: case BUILD_SNOWMAN:
case CUSTOM: case CUSTOM:
if (!area.SPAWN_CUSTOM && entity.getType().getTypeId() != 30) { if (!area.SPAWN_CUSTOM && entity.getType() != EntityType.ARMOR_STAND) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -2610,8 +2689,8 @@ import java.util.regex.Pattern;
} }
} }
return true; return true;
} else if (dplot != null && (!(dplot.equals(vplot)) || (vplot != null && Objects } else if (dplot != null && (!dplot.equals(vplot) || Objects
.equals(dplot.owner, vplot.owner)))) { .equals(dplot.guessOwner(), vplot.guessOwner()))) {
return vplot != null && Flags.PVE.isTrue(vplot); return vplot != null && Flags.PVE.isTrue(vplot);
} }
return ((vplot != null && Flags.PVE.isTrue(vplot)) || !(damager instanceof Arrow return ((vplot != null && Flags.PVE.isTrue(vplot)) || !(damager instanceof Arrow
@ -2696,7 +2775,7 @@ import java.util.regex.Pattern;
if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) { if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) {
Block block = event.getBlockPlaced(); Block block = event.getBlockPlaced();
if (block.getType().hasGravity()) { if (block.getType().hasGravity()) {
sendBlockChange(block.getLocation(), block.getType(), block.getData()); sendBlockChange(block.getLocation(), block.getBlockData());
} }
} }
} else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { } else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {

View File

@ -32,16 +32,16 @@ import java.util.UUID;
@SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener { @SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
private static final HashMap<String, Interval> feedRunnable = new HashMap<>(); private static final HashMap<UUID, Interval> feedRunnable = new HashMap<>();
private static final HashMap<String, Interval> healRunnable = new HashMap<>(); private static final HashMap<UUID, Interval> healRunnable = new HashMap<>();
public static void startRunnable(JavaPlugin plugin) { public static void startRunnable(JavaPlugin plugin) {
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override public void run() { @Override public void run() {
if (!healRunnable.isEmpty()) { if (!healRunnable.isEmpty()) {
for (Iterator<Entry<String, Interval>> iterator = for (Iterator<Entry<UUID, Interval>> iterator =
healRunnable.entrySet().iterator(); iterator.hasNext(); ) { healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
Entry<String, Interval> entry = iterator.next(); Entry<UUID, Interval> entry = iterator.next();
Interval value = entry.getValue(); Interval value = entry.getValue();
++value.count; ++value.count;
if (value.count == value.interval) { if (value.count == value.interval) {
@ -59,9 +59,9 @@ import java.util.UUID;
} }
} }
if (!feedRunnable.isEmpty()) { if (!feedRunnable.isEmpty()) {
for (Iterator<Entry<String, Interval>> iterator = for (Iterator<Entry<UUID, Interval>> iterator =
feedRunnable.entrySet().iterator(); iterator.hasNext(); ) { feedRunnable.entrySet().iterator(); iterator.hasNext(); ) {
Entry<String, Interval> entry = iterator.next(); Entry<UUID, Interval> entry = iterator.next();
Interval value = entry.getValue(); Interval value = entry.getValue();
++value.count; ++value.count;
if (value.count == value.interval) { if (value.count == value.interval) {
@ -136,20 +136,19 @@ import java.util.UUID;
Optional<Integer[]> feed = plot.getFlag(Flags.FEED); Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
if (feed.isPresent()) { if (feed.isPresent()) {
Integer[] value = feed.get(); Integer[] value = feed.get();
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20)); feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20));
} }
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL); Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
if (heal.isPresent()) { if (heal.isPresent()) {
Integer[] value = heal.get(); Integer[] value = heal.get();
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20)); healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20));
} }
} }
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String name = player.getName(); feedRunnable.remove(player.getUniqueId());
feedRunnable.remove(name); healRunnable.remove(player.getUniqueId());
healRunnable.remove(name);
} }
@EventHandler public void onPlotLeave(PlayerLeavePlotEvent event) { @EventHandler public void onPlotLeave(PlayerLeavePlotEvent event) {
@ -159,9 +158,8 @@ import java.util.UUID;
return; return;
} }
BukkitUtil.getPlayer(leaver); BukkitUtil.getPlayer(leaver);
String name = leaver.getName(); feedRunnable.remove(leaver.getUniqueId());
feedRunnable.remove(name); healRunnable.remove(leaver.getUniqueId());
healRunnable.remove(name);
} }
@EventHandler public void onItemPickup(EntityPickupItemEvent event) { @EventHandler public void onItemPickup(EntityPickupItemEvent event) {