Remove old Bukkit version support + Remove deprecated usage + cleanup code

This commit is contained in:
Marc Baloup 2017-06-11 04:44:43 +02:00
parent b8022e5ef2
commit 35e26fb045
18 changed files with 12 additions and 431 deletions

View File

@ -31,7 +31,7 @@ public class Chairs extends JavaPlugin {
public final HashSet<UUID> sitDisabled = new HashSet<>();
public final HashMap<Material, Double> validChairs = new HashMap<>();
public final List<Material> validSigns = new ArrayList<Material>();
public final List<Material> validSigns = new ArrayList<>();
public final HashSet<String> sitDisabledCommands = new HashSet<>();
public final HashSet<String> disabledWorlds = new HashSet<>();
public boolean autoRotate, signCheck, notifyplayer;

View File

@ -18,8 +18,8 @@ public class PlayerSitData {
this.plugin = plugin;
}
private HashMap<Player, SitData> sit = new HashMap<Player, SitData>();
private HashMap<Block, Player> sitblock = new HashMap<Block, Player>();
private HashMap<Player, SitData> sit = new HashMap<>();
private HashMap<Block, Player> sitblock = new HashMap<>();
public boolean isSitting(Player player) {
return sit.containsKey(player) && sit.get(player).sitting;
@ -60,7 +60,7 @@ public class PlayerSitData {
);
sitdata.resittask = task;
player.teleport(sitlocation);
arrow.setPassenger(player);
arrow.addPassenger(player);
sit.put(player, sitdata);
sitblock.put(blocktooccupy, player);
sitdata.sitting = true;
@ -72,7 +72,7 @@ public class PlayerSitData {
sitdata.sitting = false;
Entity prevarrow = sit.get(player).arrow;
Entity arrow = plugin.getNMSAccess().spawnArrow(prevarrow.getLocation());
arrow.setPassenger(player);
arrow.addPassenger(player);
sitdata.arrow = arrow;
prevarrow.remove();
sitdata.sitting = true;

View File

@ -235,11 +235,7 @@ public class TrySitEventListener implements Listener {
if (checkDirection(block, relative)) {
continue;
}
if (plugin.validSigns.contains(relative.getType())) {
return true;
} else {
return false;
}
return (plugin.validSigns.contains(relative.getType()));
}
return false;
}
@ -275,10 +271,8 @@ public class TrySitEventListener implements Listener {
}
}
}
return false;
} else {
return false;
}
return false;
}
return false;
}

View File

@ -47,8 +47,8 @@ public class TryUnsitEventListener implements Listener {
@EventHandler(priority=EventPriority.LOWEST)
public void onExitVehicle(VehicleExitEvent e) {
if (e.getVehicle().getPassenger() instanceof Player) {
final Player player = (Player) e.getVehicle().getPassenger();
if (e.getExited() instanceof Player) {
final Player player = (Player) e.getExited();
if (plugin.getPlayerSitData().isSitting(player)) {
if (!plugin.getPlayerSitData().unsitPlayer(player)) {
e.setCancelled(true);

View File

@ -1,6 +1,7 @@
package com.cnaude.chairs.sitaddons;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
@ -66,7 +67,7 @@ public class ChairEffects {
}
private double getMaxPlayerHealth(Player player) {
return ((Damageable) player).getMaxHealth();
return player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
}
public void startPickup() {

View File

@ -8,7 +8,7 @@ public class NMSAccess {
private NMSArrowFactoryInterface arrowfactory;
public void setupChairsArrow() throws NMSAccessException, ClassNotFoundException {
public void setupChairsArrow() throws NMSAccessException {
String pkgname = getClass().getPackage().getName();
String packageName = Bukkit.getServer().getClass().getPackage().getName();
String nmspackageversion = packageName.substring(packageName.lastIndexOf('.') + 1);

View File

@ -1,57 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_10_R1;
import net.minecraft.server.v1_10_R1.EntityArrow;
import java.util.Collections;
import java.util.Set;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftArrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import com.cnaude.chairs.api.ChairsAPI;
public class CraftChairsArrow extends CraftArrow implements Vehicle {
public CraftChairsArrow(CraftServer server, EntityArrow entity) {
super(server, entity);
}
@Override
public void remove() {
Entity passenger = getPassenger();
if (passenger != null && passenger instanceof Player) {
if (ChairsAPI.isSitting((Player) passenger)) {
return;
}
}
super.remove();
}
@Override
public int getPortalCooldown() {
return 0;
}
@Override
public void setPortalCooldown(int val) {
}
@Override
public Set<String> getScoreboardTags() {
return Collections.emptySet();
}
@Override
public boolean addScoreboardTag(String tag) {
return false;
}
@Override
public boolean removeScoreboardTag(String tag) {
return false;
}
}

View File

@ -1,20 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_10_R1;
import net.minecraft.server.v1_10_R1.EntityArrow;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.entity.Arrow;
import com.cnaude.chairs.vehiclearrow.NMSArrowFactoryInterface;
public class NMSArrowFactory implements NMSArrowFactoryInterface {
@Override
public Arrow spawnArrow(Location location) {
CraftWorld world = (CraftWorld) location.getWorld();
EntityArrow arrow = new NMSChairsArrow(world, location);
return (Arrow) arrow.getBukkitEntity();
}
}

View File

@ -1,23 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_10_R1;
import net.minecraft.server.v1_10_R1.EntityTippedArrow;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
public class NMSChairsArrow extends EntityTippedArrow {
public NMSChairsArrow(CraftWorld cworld, Location location) {
super(cworld.getHandle());
setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.addEntity(this);
bukkitEntity = new CraftChairsArrow((CraftServer) Bukkit.getServer(), this);
}
@Override
public void m() {
}
}

View File

@ -1,28 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_11_R1;
import com.cnaude.chairs.api.ChairsAPI;
import net.minecraft.server.v1_11_R1.EntityArrow;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftArrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
public class CraftChairsArrow extends CraftArrow implements Vehicle {
public CraftChairsArrow(CraftServer server, EntityArrow entity) {
super(server, entity);
}
@Override
public void remove() {
Entity passenger = getPassenger();
if (passenger != null && passenger instanceof Player) {
if (ChairsAPI.isSitting((Player) passenger)) {
return;
}
}
super.remove();
}
}

View File

@ -1,18 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_11_R1;
import com.cnaude.chairs.vehiclearrow.NMSArrowFactoryInterface;
import net.minecraft.server.v1_11_R1.EntityArrow;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.entity.Arrow;
public class NMSArrowFactory implements NMSArrowFactoryInterface {
@Override
public Arrow spawnArrow(Location location) {
CraftWorld world = (CraftWorld) location.getWorld();
EntityArrow arrow = new NMSChairsArrow(world, location);
return (Arrow) arrow.getBukkitEntity();
}
}

View File

@ -1,21 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_11_R1;
import net.minecraft.server.v1_11_R1.EntityTippedArrow;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
public class NMSChairsArrow extends EntityTippedArrow {
public NMSChairsArrow(CraftWorld cworld, Location location) {
super(cworld.getHandle());
setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.addEntity(this);
bukkitEntity = new CraftChairsArrow((CraftServer) Bukkit.getServer(), this);
}
@Override
public void A_() {
}
}

View File

@ -1,85 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_9_R1;
import net.minecraft.server.v1_9_R1.EntityArrow;
import java.util.Collections;
import java.util.Set;
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftArrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import com.cnaude.chairs.api.ChairsAPI;
public class CraftChairsArrow extends CraftArrow implements Vehicle {
public CraftChairsArrow(CraftServer server, EntityArrow entity) {
super(server, entity);
}
@Override
public void remove() {
Entity passenger = getPassenger();
if (passenger != null && passenger instanceof Player) {
if (ChairsAPI.isSitting((Player) passenger)) {
return;
}
}
super.remove();
}
@Override
public void setInvulnerable(boolean invulnerable) {
}
@Override
public boolean isInvulnerable() {
return true;
}
@Override
public boolean isSilent() {
return true;
}
@Override
public void setSilent(boolean silent) {
}
@Override
public boolean hasGravity() {
return false;
}
@Override
public void setGravity(boolean gravity) {
}
@Override
public int getPortalCooldown() {
return 0;
}
@Override
public void setPortalCooldown(int val) {
}
@Override
public Set<String> getScoreboardTags() {
return Collections.emptySet();
}
@Override
public boolean addScoreboardTag(String tag) {
return false;
}
@Override
public boolean removeScoreboardTag(String tag) {
return false;
}
}

View File

@ -1,20 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_9_R1;
import net.minecraft.server.v1_9_R1.EntityArrow;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.entity.Arrow;
import com.cnaude.chairs.vehiclearrow.NMSArrowFactoryInterface;
public class NMSArrowFactory implements NMSArrowFactoryInterface {
@Override
public Arrow spawnArrow(Location location) {
CraftWorld world = (CraftWorld) location.getWorld();
EntityArrow arrow = new NMSChairsArrow(world, location);
return (Arrow) arrow.getBukkitEntity();
}
}

View File

@ -1,23 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_9_R1;
import net.minecraft.server.v1_9_R1.EntityTippedArrow;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
public class NMSChairsArrow extends EntityTippedArrow {
public NMSChairsArrow(CraftWorld cworld, Location location) {
super(cworld.getHandle());
setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.addEntity(this);
bukkitEntity = new CraftChairsArrow((CraftServer) Bukkit.getServer(), this);
}
@Override
public void m() {
}
}

View File

@ -1,76 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_9_R2;
import net.minecraft.server.v1_9_R2.EntityArrow;
import java.util.Collections;
import java.util.Set;
import org.bukkit.craftbukkit.v1_9_R2.CraftServer;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftArrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import com.cnaude.chairs.api.ChairsAPI;
public class CraftChairsArrow extends CraftArrow implements Vehicle {
public CraftChairsArrow(CraftServer server, EntityArrow entity) {
super(server, entity);
}
@Override
public void remove() {
Entity passenger = getPassenger();
if (passenger != null && passenger instanceof Player) {
if (ChairsAPI.isSitting((Player) passenger)) {
return;
}
}
super.remove();
}
@Override
public boolean isSilent() {
return true;
}
@Override
public void setSilent(boolean silent) {
}
@Override
public boolean hasGravity() {
return false;
}
@Override
public void setGravity(boolean gravity) {
}
@Override
public int getPortalCooldown() {
return 0;
}
@Override
public void setPortalCooldown(int val) {
}
@Override
public Set<String> getScoreboardTags() {
return Collections.emptySet();
}
@Override
public boolean addScoreboardTag(String tag) {
return false;
}
@Override
public boolean removeScoreboardTag(String tag) {
return false;
}
}

View File

@ -1,20 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_9_R2;
import net.minecraft.server.v1_9_R2.EntityArrow;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import org.bukkit.entity.Arrow;
import com.cnaude.chairs.vehiclearrow.NMSArrowFactoryInterface;
public class NMSArrowFactory implements NMSArrowFactoryInterface {
@Override
public Arrow spawnArrow(Location location) {
CraftWorld world = (CraftWorld) location.getWorld();
EntityArrow arrow = new NMSChairsArrow(world, location);
return (Arrow) arrow.getBukkitEntity();
}
}

View File

@ -1,23 +0,0 @@
package com.cnaude.chairs.vehiclearrow.v1_9_R2;
import net.minecraft.server.v1_9_R2.EntityTippedArrow;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R2.CraftServer;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
public class NMSChairsArrow extends EntityTippedArrow {
public NMSChairsArrow(CraftWorld cworld, Location location) {
super(cworld.getHandle());
setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.addEntity(this);
bukkitEntity = new CraftChairsArrow((CraftServer) Bukkit.getServer(), this);
}
@Override
public void m() {
}
}