Drop Minecraft 1.9 support
This commit is contained in:
parent
bd57ea0728
commit
dd30f02aa2
@ -51,9 +51,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
if (minecraftVersion.isOlderThan(MinecraftVersion.v1_8))
|
if (minecraftVersion.isOlderThan(MinecraftVersion.v1_9))
|
||||||
{
|
{
|
||||||
myLogger(Level.SEVERE, "Trying to run this plugin on an unsupported version... ABORT!");
|
myLogger(Level.SEVERE, "Trying to run this plugin on an unsupported version... ABORT!");
|
||||||
|
this.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
if (compatibleMCVer())
|
if (compatibleMCVer())
|
||||||
{
|
{
|
||||||
Bukkit.getPluginManager()
|
Bukkit.getPluginManager()
|
||||||
.registerEvents(new EventHandlers(this, is1_9, config.craftingInSmithingTable()), this);
|
.registerEvents(new EventHandlers(this, config.craftingInSmithingTable()), this);
|
||||||
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this));
|
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -30,32 +30,19 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class EventHandlers implements Listener
|
public class EventHandlers implements Listener
|
||||||
{
|
{
|
||||||
private final ArmoredElytra plugin;
|
private final ArmoredElytra plugin;
|
||||||
|
|
||||||
private final Consumer<AnvilInventory> cleanAnvilInventory;
|
|
||||||
private final Consumer<Player> moveChestplateToInventory;
|
|
||||||
private final boolean creationEnabled;
|
private final boolean creationEnabled;
|
||||||
|
|
||||||
public EventHandlers(ArmoredElytra plugin, boolean is1_9, boolean creationEnabled)
|
public EventHandlers(ArmoredElytra plugin, boolean creationEnabled)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.creationEnabled = creationEnabled;
|
this.creationEnabled = creationEnabled;
|
||||||
initializeArmorEquipEvent();
|
initializeArmorEquipEvent();
|
||||||
if (is1_9)
|
|
||||||
{
|
|
||||||
cleanAnvilInventory = this::cleanAnvilOld;
|
|
||||||
moveChestplateToInventory = this::moveChestplateToInventoryOld;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cleanAnvilInventory = this::cleanAnvilNew;
|
|
||||||
moveChestplateToInventory = this::moveChestplateToInventoryNew;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeArmorEquipEvent()
|
private void initializeArmorEquipEvent()
|
||||||
@ -74,29 +61,14 @@ public class EventHandlers implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveChestplateToInventoryOld(Player player)
|
private void moveChestplateToInventory(Player player)
|
||||||
{
|
|
||||||
player.getInventory().getChestplate().setType(XMaterial.AIR.parseMaterial());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveChestplateToInventoryNew(Player player)
|
|
||||||
{
|
{
|
||||||
player.getInventory().addItem(player.getInventory().getChestplate());
|
player.getInventory().addItem(player.getInventory().getChestplate());
|
||||||
player.getInventory().getChestplate().setAmount(0);
|
player.getInventory().getChestplate().setAmount(0);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean 1.9 inventories.
|
private void cleanAnvilInventory(AnvilInventory anvilInventory)
|
||||||
private void cleanAnvilOld(AnvilInventory anvilInventory)
|
|
||||||
{
|
|
||||||
ItemStack air = new ItemStack(XMaterial.AIR.parseMaterial(), 1);
|
|
||||||
anvilInventory.setItem(0, air);
|
|
||||||
anvilInventory.setItem(1, air);
|
|
||||||
anvilInventory.setItem(2, air);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean >=1.10 inventories.
|
|
||||||
private void cleanAnvilNew(AnvilInventory anvilInventory)
|
|
||||||
{
|
{
|
||||||
if (anvilInventory.getItem(0) != null)
|
if (anvilInventory.getItem(0) != null)
|
||||||
anvilInventory.getItem(0).setAmount(0);
|
anvilInventory.getItem(0).setAmount(0);
|
||||||
@ -438,7 +410,7 @@ public class EventHandlers implements Listener
|
|||||||
player.setItemOnCursor(result);
|
player.setItemOnCursor(result);
|
||||||
|
|
||||||
// Clean the anvil's inventory after transferring the items.
|
// Clean the anvil's inventory after transferring the items.
|
||||||
cleanAnvilInventory.accept(anvilInventory);
|
cleanAnvilInventory(anvilInventory);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -503,7 +475,7 @@ public class EventHandlers implements Listener
|
|||||||
// If the durability equals/exceeds maxDurability, it's broken (0 = full item
|
// If the durability equals/exceeds maxDurability, it's broken (0 = full item
|
||||||
// durability).
|
// durability).
|
||||||
if (durability >= maxDurability)
|
if (durability >= maxDurability)
|
||||||
moveChestplateToInventory.accept(p);
|
moveChestplateToInventory(p);
|
||||||
else
|
else
|
||||||
newDurability = durability + durabilityDelta;
|
newDurability = durability + durabilityDelta;
|
||||||
}
|
}
|
||||||
@ -511,7 +483,7 @@ public class EventHandlers implements Listener
|
|||||||
if (newDurability >= maxDurability)
|
if (newDurability >= maxDurability)
|
||||||
{
|
{
|
||||||
newDurability = maxDurability;
|
newDurability = maxDurability;
|
||||||
moveChestplateToInventory.accept(p);
|
moveChestplateToInventory(p);
|
||||||
}
|
}
|
||||||
elytra.setDurability((short) (newDurability));
|
elytra.setDurability((short) (newDurability));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user