mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
And maybe like this, BP update and new item recognition method from CMI
This commit is contained in:
parent
eda39ed0d3
commit
d72f7d5f91
208
src/main/java/com/gamingmesh/jobs/CmiItems/CMIItem.java
Normal file
208
src/main/java/com/gamingmesh/jobs/CmiItems/CMIItem.java
Normal file
@ -0,0 +1,208 @@
|
||||
package com.gamingmesh.jobs.CmiItems;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.stuff.Util;
|
||||
|
||||
public class CMIItem {
|
||||
|
||||
private int id = 0;
|
||||
private short data = 0;
|
||||
private int amount = 0;
|
||||
|
||||
private String bukkitName = null;
|
||||
private Material material = null;
|
||||
private ItemStack item;
|
||||
|
||||
public CMIItem(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CMIItem clone() {
|
||||
CMIItem cm = new CMIItem(material);
|
||||
cm.setId(id);
|
||||
cm.setData(data);
|
||||
cm.setBukkitName(bukkitName);
|
||||
cm.setItemStack(this.item);
|
||||
return cm;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public short getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public boolean isTool() {
|
||||
return getMaxDurability() > 0;
|
||||
}
|
||||
|
||||
public short getDurability() {
|
||||
return this.getItemStack().getDurability();
|
||||
}
|
||||
|
||||
public short getMaxDurability() {
|
||||
return this.material.getMaxDurability();
|
||||
}
|
||||
|
||||
public void setData(short data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public CMIItem setDisplayName(String name) {
|
||||
if (name == null)
|
||||
return this;
|
||||
ItemMeta meta = this.getItemStack().getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
this.getItemStack().setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
ItemMeta meta = this.getItemStack().getItemMeta();
|
||||
return meta.getDisplayName() == null ? this.getRealName() : meta.getDisplayName();
|
||||
}
|
||||
|
||||
public CMIItem addLore(String string) {
|
||||
if (string == null)
|
||||
return this;
|
||||
ItemMeta meta = this.getItemStack().getItemMeta();
|
||||
List<String> lore = meta.getLore();
|
||||
if (lore == null)
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', string));
|
||||
meta.setLore(lore);
|
||||
this.getItemStack().setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CMIItem setLore(List<String> lore) {
|
||||
if (lore == null)
|
||||
return this;
|
||||
ItemMeta meta = this.getItemStack().getItemMeta();
|
||||
List<String> t = new ArrayList<String>();
|
||||
for (String one : lore) {
|
||||
t.add(ChatColor.translateAlternateColorCodes('&', one));
|
||||
}
|
||||
meta.setLore(t);
|
||||
this.getItemStack().setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CMIItem addEnchant(Enchantment enchant, Integer level) {
|
||||
if (enchant == null)
|
||||
return this;
|
||||
ItemMeta meta = this.getItemStack().getItemMeta();
|
||||
meta.addEnchant(enchant, level, true);
|
||||
this.getItemStack().setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CMIItem addEnchant(HashMap<Enchantment, Integer> enchants) {
|
||||
if (enchants == null || enchants.isEmpty())
|
||||
return this;
|
||||
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
|
||||
this.addEnchant(oneEnch.getKey(), oneEnch.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CMIItem clearEnchants() {
|
||||
ItemMeta meta = this.getItemStack().getItemMeta();
|
||||
meta.getEnchants().clear();
|
||||
this.getItemStack().setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getLore() {
|
||||
ItemMeta meta = this.getItemStack().getItemMeta();
|
||||
return meta.getLore();
|
||||
}
|
||||
|
||||
public String getRealName() {
|
||||
return Jobs.getItemManager().getRealName(this, true).getName();
|
||||
}
|
||||
|
||||
public String getBukkitName() {
|
||||
return bukkitName;
|
||||
}
|
||||
|
||||
public void setBukkitName(String bukkitName) {
|
||||
this.bukkitName = bukkitName;
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
if (item == null) {
|
||||
this.item = new ItemStack(material, this.amount == 0 ? 1 : this.amount, data);
|
||||
}
|
||||
|
||||
if (this.item.getType() == Material.MOB_SPAWNER) {
|
||||
if (data == 0)
|
||||
data = 90;
|
||||
EntityType type = EntityType.fromId(data);
|
||||
if (type != null)
|
||||
this.item = Util.setEntityType(this.item, type);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public CMIItem setItemStack(ItemStack item) {
|
||||
this.item = item;
|
||||
if (item != null) {
|
||||
this.amount = item.getAmount();
|
||||
if ((material.isBlock() || material.isSolid()))
|
||||
data = item.getData().getData();
|
||||
if (item.getType().getMaxDurability() - item.getDurability() < 0)
|
||||
data = item.getDurability();
|
||||
if (item.getType() == Material.MOB_SPAWNER)
|
||||
data = Util.getEntityType(item).getTypeId();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public boolean isSimilar(ItemStack item) {
|
||||
return isSimilar(Jobs.getItemManager().getItem(item));
|
||||
}
|
||||
|
||||
public boolean isSimilar(CMIItem item) {
|
||||
if (item == null)
|
||||
return false;
|
||||
return this.getMaterial().equals(item.material) && this.getData() == item.getData();
|
||||
}
|
||||
|
||||
}
|
1090
src/main/java/com/gamingmesh/jobs/CmiItems/ItemManager.java
Normal file
1090
src/main/java/com/gamingmesh/jobs/CmiItems/ItemManager.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -39,6 +39,7 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.gamingmesh.jobs.CmiItems.ItemManager;
|
||||
import com.gamingmesh.jobs.Gui.GuiManager;
|
||||
import com.gamingmesh.jobs.MyPet.MyPetManager;
|
||||
import com.gamingmesh.jobs.MythicMobs.MythicMobInterface;
|
||||
@ -136,6 +137,8 @@ public class Jobs extends JavaPlugin {
|
||||
private static PermissionHandler permissionHandler;
|
||||
private static PermissionManager permissionManager;
|
||||
|
||||
private static ItemManager itemManager;
|
||||
|
||||
public static BufferedPaymentThread paymentThread = null;
|
||||
private static DatabaseSaveThread saveTask = null;
|
||||
|
||||
@ -673,6 +676,10 @@ public class Jobs extends JavaPlugin {
|
||||
return permissionManager;
|
||||
}
|
||||
|
||||
public static ItemManager getItemManager() {
|
||||
return itemManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the economy handler
|
||||
* @param eco - the economy handler
|
||||
@ -704,6 +711,8 @@ public class Jobs extends JavaPlugin {
|
||||
versionCheckManager = new VersionChecker(this);
|
||||
version = versionCheckManager.getVersion().getShortVersion();
|
||||
|
||||
itemManager = new ItemManager(this);
|
||||
|
||||
try {
|
||||
Class<?> nmsClass;
|
||||
nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version);
|
||||
@ -1059,64 +1068,68 @@ public class Jobs extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean isBpOk(Player player, ActionInfo info, Block block, boolean inform) {
|
||||
if ((block != null) && (getGCManager().useBlockProtection)) {
|
||||
if (info.getType() == ActionType.BREAK) {
|
||||
BlockProtection bp = getBpManager().getBp(block.getLocation());
|
||||
if (bp != null) {
|
||||
Long time = bp.getTime();
|
||||
if (time == -1L) {
|
||||
return false;
|
||||
if (block == null || !getGCManager().useBlockProtection)
|
||||
return true;
|
||||
|
||||
if (info.getType() == ActionType.BREAK) {
|
||||
BlockProtection bp = getBpManager().getBp(block.getLocation());
|
||||
if (bp != null) {
|
||||
Long time = bp.getTime();
|
||||
Integer cd = getBpManager().getBlockDelayTime(block);
|
||||
|
||||
if (time == -1L) {
|
||||
getBpManager().add(block, cd);
|
||||
return false;
|
||||
}
|
||||
if ((time < System.currentTimeMillis()) && (bp.getAction() != DBAction.DELETE)) {
|
||||
getBpManager().remove(block);
|
||||
return true;
|
||||
}
|
||||
if (time > System.currentTimeMillis() || bp.isPaid() && bp.getAction() != DBAction.DELETE) {
|
||||
int sec = Math.round((time - System.currentTimeMillis()) / 1000L);
|
||||
if (inform) {
|
||||
getActionBar().send(player, getLanguage().getMessage("message.blocktimer", "[time]", sec));
|
||||
}
|
||||
Integer cd = getBpManager().getBlockDelayTime(block);
|
||||
if ((time < System.currentTimeMillis()) && (bp.getAction() != DBAction.DELETE)) {
|
||||
getBpManager().remove(block);
|
||||
return false;
|
||||
}
|
||||
getBpManager().add(block, cd);
|
||||
if (cd == 0 && getGCManager().useGlobalTimer) {
|
||||
getBpManager().add(block, getGCManager().globalblocktimer);
|
||||
}
|
||||
} else if (getGCManager().useGlobalTimer) {
|
||||
getBpManager().add(block, getGCManager().globalblocktimer);
|
||||
}
|
||||
} else if (info.getType() == ActionType.PLACE) {
|
||||
BlockProtection bp = getBpManager().getBp(block.getLocation());
|
||||
if (bp != null) {
|
||||
Long time = bp.getTime();
|
||||
Integer cd = getBpManager().getBlockDelayTime(block);
|
||||
|
||||
if (time != -1L) {
|
||||
if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) {
|
||||
getBpManager().add(block, cd);
|
||||
return true;
|
||||
}
|
||||
if (((time > System.currentTimeMillis()) || (bp.isPaid().booleanValue())) && (bp.getAction() != DBAction.DELETE)) {
|
||||
if (time > System.currentTimeMillis() || bp.isPaid() && bp.getAction() != DBAction.DELETE) {
|
||||
int sec = Math.round((time - System.currentTimeMillis()) / 1000L);
|
||||
if (inform) {
|
||||
getActionBar().send(player, getLanguage().getMessage("message.blocktimer", new Object[] { "[time]", Integer.valueOf(sec) }));
|
||||
getActionBar().send(player, getLanguage().getMessage("message.blocktimer", "[time]", sec));
|
||||
}
|
||||
getBpManager().add(block, cd);
|
||||
return false;
|
||||
}
|
||||
} else if (bp.isPaid().booleanValue() && bp.getTime() == -1L && cd != null && cd == -1) {
|
||||
getBpManager().add(block, cd);
|
||||
if ((cd == null) &&
|
||||
(getGCManager().useGlobalTimer)) {
|
||||
getBpManager().add(block, Long.valueOf(System.currentTimeMillis() + getGCManager().globalblocktimer * 1000));
|
||||
}
|
||||
} else if (getGCManager().useGlobalTimer) {
|
||||
getBpManager().add(block, Long.valueOf(System.currentTimeMillis() + getGCManager().globalblocktimer * 1000));
|
||||
}
|
||||
} else if (info.getType() == ActionType.PLACE) {
|
||||
BlockProtection bp = getBpManager().getBp(block.getLocation());
|
||||
if (bp != null) {
|
||||
Long time = bp.getTime();
|
||||
if (time != -1L) {
|
||||
if ((time < System.currentTimeMillis()) && (bp.getAction() != DBAction.DELETE)) {
|
||||
getBpManager().add(block, getBpManager().getBlockDelayTime(block));
|
||||
return true;
|
||||
}
|
||||
if (((time > System.currentTimeMillis()) || (bp.isPaid().booleanValue())) && (bp.getAction() != DBAction.DELETE)) {
|
||||
int sec = Math.round((time - System.currentTimeMillis()) / 1000L);
|
||||
|
||||
Debug.D((time - System.currentTimeMillis()) + " " + bp.isPaid().booleanValue() + bp.getAction());
|
||||
|
||||
if (inform) {
|
||||
getActionBar().send(player, getLanguage().getMessage("message.blocktimer", new Object[] { "[time]", Integer.valueOf(sec) }));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if ((bp.isPaid().booleanValue()) &&
|
||||
(bp.getTime() == -1L) && (getBpManager().getBlockDelayTime(block) != null) && (getBpManager().getBlockDelayTime(block).intValue() == -1)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
getBpManager().add(block, getBpManager().getBlockDelayTime(block));
|
||||
}
|
||||
return false;
|
||||
} else
|
||||
getBpManager().add(block, cd);
|
||||
} else {
|
||||
getBpManager().add(block, getBpManager().getBlockDelayTime(block));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,9 @@ public class bp implements Cmd {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
|
||||
return false;
|
||||
}
|
||||
boolean all = false;
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("-a"))
|
||||
all = true;
|
||||
|
||||
final Player player = (Player) sender;
|
||||
|
||||
@ -40,14 +43,18 @@ public class bp implements Cmd {
|
||||
BlockProtection bp = Jobs.getBpManager().getBp(l);
|
||||
if (bp != null) {
|
||||
Long time = bp.getTime();
|
||||
if (bp.getAction() == DBAction.DELETE)
|
||||
continue;
|
||||
if (time != -1 && time < System.currentTimeMillis()) {
|
||||
Jobs.getBpManager().remove(l);
|
||||
continue;
|
||||
if (!all) {
|
||||
if (bp.getAction() == DBAction.DELETE)
|
||||
continue;
|
||||
if (time != -1 && time < System.currentTimeMillis()) {
|
||||
Jobs.getBpManager().remove(l);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
changedBlocks.add(l.getBlock());
|
||||
if (time == -1)
|
||||
if (bp.getAction() == DBAction.DELETE)
|
||||
player.sendBlockChange(l, Material.STAINED_GLASS, (byte) 14);
|
||||
else if (time == -1)
|
||||
player.sendBlockChange(l, Material.STAINED_GLASS, (byte) 15);
|
||||
else
|
||||
player.sendBlockChange(l, Material.STAINED_GLASS, (byte) 0);
|
||||
@ -68,7 +75,7 @@ public class bp implements Cmd {
|
||||
}
|
||||
}
|
||||
}, 120L);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -38,40 +38,48 @@ public class BlockProtectionManager {
|
||||
return i;
|
||||
}
|
||||
|
||||
public void add(Block block, boolean paid) {
|
||||
add(block, -1L, paid);
|
||||
}
|
||||
// public void add(Block block, boolean paid) {
|
||||
// add(block, -1L, paid);
|
||||
// }
|
||||
//
|
||||
// public void add(Block block) {
|
||||
// add(block, -1L, true);
|
||||
// }
|
||||
|
||||
public void add(Block block) {
|
||||
add(block, -1L, true);
|
||||
}
|
||||
|
||||
public void add(Block block, Long time, boolean paid) {
|
||||
add(block.getLocation(), time, paid);
|
||||
}
|
||||
// public void add(Block block, Long time, boolean paid) {
|
||||
// add(block.getLocation(), time, paid);
|
||||
// }
|
||||
|
||||
public void add(Block block, Integer cd) {
|
||||
add(block, cd, true);
|
||||
}
|
||||
|
||||
public void add(Block block, Integer cd, boolean paid) {
|
||||
add(block.getLocation(), cd, paid);
|
||||
}
|
||||
|
||||
public void add(Location loc, Integer cd) {
|
||||
add(loc, cd, true);
|
||||
}
|
||||
|
||||
public void add(Location loc, Integer cd, boolean paid) {
|
||||
if (cd == null)
|
||||
return;
|
||||
if (cd != -1)
|
||||
add(block, System.currentTimeMillis() + (cd * 1000), paid);
|
||||
addP(loc, System.currentTimeMillis() + (cd * 1000), paid);
|
||||
else
|
||||
add(block, paid);
|
||||
addP(loc, -1L, paid);
|
||||
}
|
||||
|
||||
public void add(Block block, Long time) {
|
||||
add(block.getLocation(), time, true);
|
||||
}
|
||||
// public void add(Block block, Long time) {
|
||||
// add(block.getLocation(), time, true);
|
||||
// }
|
||||
//
|
||||
// public void add(Location loc, Long time) {
|
||||
// add(loc, time, true);
|
||||
// }
|
||||
|
||||
public void add(Location loc, Long time) {
|
||||
add(loc, time, true);
|
||||
}
|
||||
|
||||
public BlockProtection add(Location loc, Long time, boolean paid) {
|
||||
public BlockProtection addP(Location loc, Long time, boolean paid) {
|
||||
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> regions = map.get(loc.getWorld());
|
||||
if (regions == null)
|
||||
@ -145,14 +153,8 @@ public class BlockProtectionManager {
|
||||
return null;
|
||||
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||
BlockProtection Bp = chunk.get(v);
|
||||
|
||||
if (Bp == null)
|
||||
return null;
|
||||
Debug.D("by " + v);
|
||||
Debug.D("got " + Bp.getPos().toString());
|
||||
for (Entry<String, BlockProtection> one : chunk.entrySet()) {
|
||||
Debug.D("g " + one.getKey());
|
||||
}
|
||||
return Bp;
|
||||
}
|
||||
|
||||
@ -171,7 +173,8 @@ public class BlockProtectionManager {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Integer getBlockDelayTime(Block block) {
|
||||
return Jobs.getRestrictedBlockManager().restrictedBlocksTimer.get(block.getTypeId());
|
||||
Integer c = Jobs.getRestrictedBlockManager().restrictedBlocksTimer.get(block.getTypeId());
|
||||
return c == null ? 0 : c;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -73,6 +73,7 @@ public class LanguageManager {
|
||||
|
||||
c.get("economy.error.nomoney", "&cSorry, no money left in national bank!");
|
||||
c.get("limitedItem.error.levelup", "&cYou need to levelup in [jobname] to use this item!");
|
||||
c.get("general.Spawner", "&r[type] Spawner");
|
||||
c.get("general.info.toplineseparator", "&7*********************** &6%playername% &7***********************");
|
||||
c.get("general.info.separator", "&7*******************************************************");
|
||||
c.get("general.info.time.day", "&e%days% &6days ");
|
||||
|
@ -6,10 +6,10 @@ import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.CmiItems.CMIItem;
|
||||
import com.gamingmesh.jobs.container.LocaleReader;
|
||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||
|
||||
@ -28,7 +28,6 @@ public class RestrictedBlockManager {
|
||||
*
|
||||
* loads from Jobs/restrictedAreas.yml
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public synchronized void load() {
|
||||
File f = new File(plugin.getDataFolder(), "restrictedBlocks.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
|
||||
@ -151,20 +150,19 @@ public class RestrictedBlockManager {
|
||||
c.getC().addDefault("blocksTimer.emeraldore.cd", -1);
|
||||
c.getC().addDefault("blocksTimer.quartzore.id", "quartzore");
|
||||
c.getC().addDefault("blocksTimer.quartzore.cd", -1);
|
||||
|
||||
}
|
||||
|
||||
if (c.getC().isConfigurationSection("blocksTimer")) {
|
||||
Set<String> lss = c.getC().getConfigurationSection("blocksTimer").getKeys(false);
|
||||
for (String one : lss) {
|
||||
if (((c.getC().isString("blocksTimer." + one + ".id")) || (c.getC().isInt("blocksTimer." + one + ".id"))) && (c.getC().isInt("blocksTimer." + one
|
||||
+ ".cd"))) {
|
||||
Material mat = getMaterial(c.getC().getString("blocksTimer." + one + ".id"));
|
||||
if ((mat == null) || (!mat.isBlock())) {
|
||||
+ ".cd"))) {
|
||||
CMIItem cm = Jobs.getItemManager().getItem(c.getC().getString("blocksTimer." + one + ".id"));
|
||||
if ((cm == null) || (!cm.getMaterial().isBlock())) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[Jobs] Your defined (" + c.getC().getString(new StringBuilder("blocksTimer.").append(one)
|
||||
.append(".id").toString()) + ") protected block id/name is not correct!");
|
||||
} else {
|
||||
this.restrictedBlocksTimer.put(mat.getId(), c.getC().getInt("blocksTimer." + one + ".cd"));
|
||||
this.restrictedBlocksTimer.put(cm.getId(), c.getC().getInt("blocksTimer." + one + ".cd"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,29 +176,4 @@ public class RestrictedBlockManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Material getMaterial(String id) {
|
||||
id = id.replace("_", "").replace(" ", "");
|
||||
Material material = null;
|
||||
|
||||
for (Material one : Material.values()) {
|
||||
if (one.name().replace("_", "").equalsIgnoreCase(id)) {
|
||||
material = one;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (material == null) {
|
||||
Integer matId = null;
|
||||
try {
|
||||
matId = Integer.valueOf(id);
|
||||
} catch (NumberFormatException localNumberFormatException) {
|
||||
}
|
||||
if (matId != null) {
|
||||
material = Material.getMaterial(matId);
|
||||
}
|
||||
}
|
||||
return material;
|
||||
}
|
||||
}
|
||||
|
@ -1263,7 +1263,7 @@ public abstract class JobsDAO {
|
||||
int z = res.getInt("z");
|
||||
long resets = res.getLong("resets");
|
||||
Location loc = new Location(world, x, y, z);
|
||||
BlockProtection bp = Jobs.getBpManager().add(loc, resets, true);
|
||||
BlockProtection bp = Jobs.getBpManager().addP(loc, resets, true);
|
||||
bp.setId(id);
|
||||
long t = System.currentTimeMillis();
|
||||
bp.setRecorded(res.getLong("recorded"));
|
||||
|
@ -44,13 +44,14 @@ public class PistonProtectionListener implements Listener {
|
||||
|
||||
Long bp = Jobs.getBpManager().getTime(oldLoc);
|
||||
if (bp != null) {
|
||||
Jobs.getBpManager().add(newLoc, bp);
|
||||
Jobs.getBpManager().addP(newLoc, bp, true);
|
||||
Jobs.getBpManager().remove(oldLoc);
|
||||
} else {
|
||||
Integer cd = Jobs.getBpManager().getBlockDelayTime(one);
|
||||
if (cd != null)
|
||||
Jobs.getBpManager().add(newLoc, System.currentTimeMillis() + (cd * 1000));
|
||||
Jobs.getBpManager().add(newLoc, cd);
|
||||
else if (Jobs.getGCManager().useGlobalTimer)
|
||||
Jobs.getBpManager().add(newLoc, System.currentTimeMillis() + (Jobs.getGCManager().globalblocktimer * 1000));
|
||||
Jobs.getBpManager().add(newLoc, Jobs.getGCManager().globalblocktimer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,13 +79,14 @@ public class PistonProtectionListener implements Listener {
|
||||
Location newLoc = oldLoc.clone().add(x, y, z);
|
||||
Long bp = Jobs.getBpManager().getTime(oldLoc);
|
||||
if (bp != null) {
|
||||
Jobs.getBpManager().add(newLoc, bp);
|
||||
Jobs.getBpManager().addP(newLoc, bp, true);
|
||||
Jobs.getBpManager().remove(oldLoc);
|
||||
} else {
|
||||
Integer cd = Jobs.getBpManager().getBlockDelayTime(one);
|
||||
if (cd != null)
|
||||
Jobs.getBpManager().add(newLoc, System.currentTimeMillis() + (cd * 1000));
|
||||
Jobs.getBpManager().add(newLoc, cd);
|
||||
else if (Jobs.getGCManager().useGlobalTimer)
|
||||
Jobs.getBpManager().add(newLoc, System.currentTimeMillis() + (Jobs.getGCManager().globalblocktimer * 1000));
|
||||
Jobs.getBpManager().add(newLoc, Jobs.getGCManager().globalblocktimer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,26 +13,26 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class GiveItem {
|
||||
public static boolean GiveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore, HashMap<Enchantment, Integer> hashMap) {
|
||||
@SuppressWarnings("deprecation")
|
||||
ItemStack itemStack = new ItemStack(Material.getMaterial(id), qty, (short) meta);
|
||||
ItemMeta ItemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (lore != null) {
|
||||
List<String> TranslatedLore = new ArrayList<String>();
|
||||
for (String oneLore : lore) {
|
||||
TranslatedLore.add(ChatColor.translateAlternateColorCodes('&', oneLore.replace("[player]", player.getName())));
|
||||
}
|
||||
ItemMeta.setLore(TranslatedLore);
|
||||
}
|
||||
for (Entry<Enchantment, Integer> OneEnchant : hashMap.entrySet()) {
|
||||
ItemMeta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true);
|
||||
}
|
||||
if (name != null)
|
||||
ItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
itemStack.setItemMeta(ItemMeta);
|
||||
player.getInventory().addItem(itemStack);
|
||||
player.getPlayer().updateInventory();
|
||||
return true;
|
||||
public static boolean GiveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore, HashMap<Enchantment, Integer> hashMap) {
|
||||
@SuppressWarnings("deprecation")
|
||||
ItemStack itemStack = new ItemStack(Material.getMaterial(id), qty, (short) meta);
|
||||
ItemMeta ItemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (lore != null) {
|
||||
List<String> TranslatedLore = new ArrayList<String>();
|
||||
for (String oneLore : lore) {
|
||||
TranslatedLore.add(ChatColor.translateAlternateColorCodes('&', oneLore.replace("[player]", player.getName())));
|
||||
}
|
||||
ItemMeta.setLore(TranslatedLore);
|
||||
}
|
||||
for (Entry<Enchantment, Integer> OneEnchant : hashMap.entrySet()) {
|
||||
ItemMeta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true);
|
||||
}
|
||||
if (name != null)
|
||||
ItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
itemStack.setItemMeta(ItemMeta);
|
||||
player.getInventory().addItem(itemStack);
|
||||
player.getPlayer().updateInventory();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
56
src/main/java/com/gamingmesh/jobs/stuff/Util.java
Normal file
56
src/main/java/com/gamingmesh/jobs/stuff/Util.java
Normal file
@ -0,0 +1,56 @@
|
||||
package com.gamingmesh.jobs.stuff;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class Util {
|
||||
|
||||
public Util() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack setEntityType(ItemStack is, EntityType type) throws IllegalArgumentException {
|
||||
boolean useMeta;
|
||||
try {
|
||||
ItemStack testis = new ItemStack(Material.MOB_SPAWNER, 1);
|
||||
ItemMeta meta = testis.getItemMeta();
|
||||
useMeta = meta instanceof BlockStateMeta;
|
||||
} catch (Exception e) {
|
||||
useMeta = false;
|
||||
}
|
||||
|
||||
if (useMeta) {
|
||||
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
|
||||
BlockState bs = bsm.getBlockState();
|
||||
((CreatureSpawner) bs).setSpawnedType(type);
|
||||
((CreatureSpawner) bs).setCreatureTypeByName(type.name());
|
||||
bsm.setBlockState(bs);
|
||||
|
||||
String cap = type.name().toLowerCase().replace("_", " ").substring(0, 1).toUpperCase() + type.name().toLowerCase().replace("_", " ").substring(1);
|
||||
bsm.setDisplayName(Jobs.getLanguage().getMessage("general.Spawner", "[type]", cap));
|
||||
is.setItemMeta(bsm);
|
||||
} else {
|
||||
is.setDurability(type.getTypeId());
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static EntityType getEntityType(ItemStack is) {
|
||||
if (is.getItemMeta() instanceof BlockStateMeta) {
|
||||
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
|
||||
if (bsm.getBlockState() instanceof CreatureSpawner) {
|
||||
CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
|
||||
return bs.getSpawnedType();
|
||||
}
|
||||
}
|
||||
return EntityType.fromId(is.getData().getData());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user