mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 18:55:11 +01:00
added durability fix
This commit is contained in:
parent
b9dce03af5
commit
490f9406c3
@ -12,6 +12,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@ -290,4 +291,19 @@ public class Utils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixDurability(final ItemStack item) {
|
||||
if (item == null || item.getType().getMaxDurability() == 0)
|
||||
return;
|
||||
final short old = item.getDurability();
|
||||
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int diff = old - item.getDurability();
|
||||
if (diff != 0) {
|
||||
item.setDurability((short) (item.getDurability() + diff));
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package fr.xephi.authme.listener;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class AuthMeBlockListener implements Listener {
|
||||
|
||||
@ -25,8 +27,11 @@ public class AuthMeBlockListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer()))
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player)) {
|
||||
return;
|
||||
}
|
||||
Utils.fixDurability(player.getItemInHand());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.player.PlayerEggThrowEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class AuthMeEntityListener implements Listener {
|
||||
|
||||
@ -29,7 +29,11 @@ public class AuthMeEntityListener implements Listener {
|
||||
if (Utils.checkAuth(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack item : player.getInventory().getArmorContents()) {
|
||||
if (item != null) {
|
||||
Utils.fixDurability(item);
|
||||
}
|
||||
}
|
||||
player.setFireTicks(0);
|
||||
event.setDamage(0.0);
|
||||
event.setCancelled(true);
|
||||
@ -57,10 +61,12 @@ public class AuthMeEntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Utils.checkAuth((Player) entity)) {
|
||||
Player player = (Player) entity;
|
||||
if (Utils.checkAuth(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Utils.fixDurability(player.getItemInHand());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -134,4 +140,21 @@ public class AuthMeEntityListener implements Listener {
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onShoot(EntityShootBowEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity == null || !(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) entity;
|
||||
if (Utils.checkAuth(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Utils.fixDurability(player.getItemInHand());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@ -400,8 +401,14 @@ public class AuthMePlayerListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer()))
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
return;
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Utils.fixDurability(player.getItemInHand());
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -487,7 +494,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (Utils.checkAuth(player))
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
return;
|
||||
String name = player.getName().toLowerCase();
|
||||
Location spawn = plugin.getSpawnLocation(player);
|
||||
@ -517,4 +524,22 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerShear(PlayerShearEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
return;
|
||||
Utils.fixDurability(player.getItemInHand());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerFish(PlayerFishEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
return;
|
||||
Utils.fixDurability(player.getItemInHand());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user