Remove Repair functionality from Gameplay class
This commit is contained in:
parent
5045bad684
commit
a952ee31cd
@ -1,44 +1,8 @@
|
||||
package mineplex.game.clans.gameplay;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.common.util.UtilGear;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilItem;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.weight.Weight;
|
||||
import mineplex.core.common.weight.WeightSet;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.game.clans.clans.ClanInfo;
|
||||
import mineplex.game.clans.clans.ClansManager;
|
||||
import mineplex.game.clans.clans.event.ClansWaterPlaceEvent;
|
||||
import mineplex.game.clans.clans.event.IronDoorOpenEvent;
|
||||
import mineplex.game.clans.core.repository.ClanTerritory;
|
||||
import mineplex.game.clans.items.GearManager;
|
||||
import mineplex.minecraft.game.classcombat.Class.ClientClass;
|
||||
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
|
||||
import mineplex.minecraft.game.classcombat.Skill.event.BlockTossEvent;
|
||||
import mineplex.minecraft.game.classcombat.Skill.event.BlockTossLandEvent;
|
||||
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
||||
import mineplex.minecraft.game.core.damage.DamageManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
@ -66,19 +30,41 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent.State;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.material.Dye;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilItem;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.weight.Weight;
|
||||
import mineplex.core.common.weight.WeightSet;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.game.clans.clans.ClanInfo;
|
||||
import mineplex.game.clans.clans.ClansManager;
|
||||
import mineplex.game.clans.clans.event.ClansWaterPlaceEvent;
|
||||
import mineplex.game.clans.clans.event.IronDoorOpenEvent;
|
||||
import mineplex.game.clans.core.repository.ClanTerritory;
|
||||
import mineplex.minecraft.game.classcombat.Class.ClientClass;
|
||||
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
|
||||
import mineplex.minecraft.game.classcombat.Skill.event.BlockTossEvent;
|
||||
import mineplex.minecraft.game.classcombat.Skill.event.BlockTossLandEvent;
|
||||
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
||||
import mineplex.minecraft.game.core.damage.DamageManager;
|
||||
|
||||
public class Gameplay extends MiniPlugin
|
||||
{
|
||||
private static final int MAX_BUILD_HEIGHT = 120;
|
||||
@ -102,6 +88,7 @@ public class Gameplay extends MiniPlugin
|
||||
// Register the custom recipes and mobs
|
||||
Bukkit.getPluginManager().registerEvents(new CustomRecipes(), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomCreatures(), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new DurabilityManager(), plugin);
|
||||
}
|
||||
|
||||
// @EventHandler(priority = EventPriority.LOWEST)
|
||||
@ -760,116 +747,6 @@ public class Gameplay extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void Repair(PlayerInteractEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (event.getClickedBlock() == null || event.getClickedBlock().getType() != Material.ANVIL || !UtilEvent.isAction(event, ActionType.R_BLOCK) || player.isSneaking() || player.getItemInHand().getType() == Material.AIR)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilMath.offset(player.getLocation(), event.getClickedBlock().getLocation()) > 2)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "You are too far from the " + F.item("Anvil") + "."));
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
if (item.getDurability() <= 0)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "Your " + F.item(item == null ? ChatColor.YELLOW + "Hand" : item.getItemMeta().getDisplayName()) + " does not need repairs."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UtilGear.isRepairable(item))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "You cannot repair " + F.item(item.getItemMeta().getDisplayName()) + "."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (GearManager.isCustomItem(item))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "You cannot repair " + F.item(item.getItemMeta().getDisplayName()) + "."));
|
||||
return;
|
||||
}
|
||||
|
||||
int repairs = ItemStackFactory.Instance.GetLoreVar(item, "Repaired", 0);
|
||||
boolean canRepair = canRepair(item);
|
||||
|
||||
if (!canRepair)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "This item cannot be repaired anymore."));
|
||||
return;
|
||||
}
|
||||
|
||||
String creator = ItemStackFactory.Instance.GetLoreVar(item, "Owner");
|
||||
|
||||
if (creator != null)
|
||||
{
|
||||
if (creator.length() > 2) creator = creator.substring(2, creator.length());
|
||||
|
||||
if (!creator.equals(player.getName()))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "You cannot repair " + F.item(item.getItemMeta().getDisplayName()) + " by " + F.name(creator) + "."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_blockRestore.contains(event.getClickedBlock()))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "You cannot repair using that anvil"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Repair!
|
||||
UtilPlayer.message(player, F.main("Repair", "You repaired " + F.item(item.getItemMeta().getDisplayName()) + "."));
|
||||
item.setDurability((short) 0);
|
||||
UtilInv.Update(player);
|
||||
|
||||
// Break
|
||||
if (Math.random() > 0.85)
|
||||
{
|
||||
byte data = event.getClickedBlock().getData();
|
||||
if (data >= 8) // Anvil has already been damaged twice
|
||||
{
|
||||
player.getWorld().playEffect(event.getClickedBlock().getLocation(), Effect.STEP_SOUND, 145);
|
||||
event.getClickedBlock().setType(Material.AIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
event.getClickedBlock().setData((byte)(data + 4));
|
||||
}
|
||||
}
|
||||
|
||||
// Record
|
||||
ItemStackFactory.Instance.SetLoreVar(item, "Repaired", (repairs + 1) + "");
|
||||
if (!canRepair(item))
|
||||
{
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.getLore().add(ChatColor.BLUE + "Nonfixable");
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
// Effect
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_USE, 1f, 1f);
|
||||
}
|
||||
|
||||
private boolean canRepair(ItemStack item)
|
||||
{
|
||||
int repairs = ItemStackFactory.Instance.GetLoreVar(item, "Repaired", 0);
|
||||
boolean gold = UtilGear.isGold(item);
|
||||
boolean canRepair = true;
|
||||
|
||||
if (repairs >= 3 && gold)
|
||||
canRepair = false;
|
||||
else if (repairs >= 2 && !gold) canRepair = false;
|
||||
|
||||
return canRepair;
|
||||
}
|
||||
|
||||
public DamageManager getDamageManager()
|
||||
{
|
||||
return _damageManager;
|
||||
|
Loading…
Reference in New Issue
Block a user