Updated Item Cube handling. No longer allows multiple players to view

the same inventory at the same time. Plays an error sound and displays a
message when attempting to do so. This prevents bugs. In addition, allow
item cubes to be handled inside ender item cubes. Add in missing checks
for item cube validation and fix up crafting recipes involving item
cubes. Finally, added a recipe that allows you to duplicate an ender
item cube using a nether star (shapeless)
This commit is contained in:
sigonasr2 2016-06-27 23:53:48 -05:00
parent efc9b09a1e
commit a2bf6fda88
7 changed files with 372 additions and 254 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: TwosideKeeper name: TwosideKeeper
main: sig.plugin.TwosideKeeper.TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper
version: 3.4.2 version: 3.4.3
commands: commands:
money: money:
description: Tells the player the amount of money they are holding. description: Tells the player the amount of money they are holding.

View File

@ -174,7 +174,9 @@ public class Artifact {
return item; return item;
} }
public static boolean isArtifact(ItemStack item) { public static boolean isArtifact(ItemStack item) {
if (item.hasItemMeta() && if (item!=null &&
item.getType()!=Material.AIR &&
item.hasItemMeta() &&
item.getItemMeta().hasLore() && item.getItemMeta().hasLore() &&
(item.getItemMeta().getLore().contains(ChatColor.GOLD+""+ChatColor.ITALIC+"Artifact Crafting Item") || (item.getItemMeta().getLore().contains(ChatColor.GOLD+""+ChatColor.ITALIC+"Artifact Crafting Item") ||
item.getItemMeta().getLore().contains(ChatColor.GOLD+""+ChatColor.ITALIC+"Artifact Item"))) { item.getItemMeta().getLore().contains(ChatColor.GOLD+""+ChatColor.ITALIC+"Artifact Item"))) {

View File

@ -0,0 +1,29 @@
package sig.plugin.TwosideKeeper.HelperStructures;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import com.google.common.collect.Iterables;
public class ItemCube {
public static boolean isSomeoneViewingItemCube(int id, Player checker) {
for (int i=0;i<Bukkit.getOnlinePlayers().size();i++) {
Player p = Iterables.get(Bukkit.getOnlinePlayers(), i);
if (!p.equals(checker)) {
if (p.getOpenInventory()!=null && p.getOpenInventory().getTitle().contains("Item Cube #")) {
//This is an item cube. Check if it's the same number.
int ider = Integer.parseInt(p.getOpenInventory().getTitle().split("#")[1]);
if (ider==id) {
return true;
}
}
}
}
return false; //Didn't find anyone, oh well..
}
public static void displayErrorMessage(Player p) {
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 0.6f, 4.0f);
p.sendMessage("Someone is currently using this Item Cube! Please wait for them to finish.");
}
}

View File

@ -65,6 +65,12 @@ public class Recipes {
Bukkit.addRecipe(ItemCube); Bukkit.addRecipe(ItemCube);
//------------------------------ //------------------------------
ItemStack item_ItemCube1 = new ItemStack(Material.ENDER_CHEST,2);
ShapelessRecipe ItemCube1 = new ShapelessRecipe(item_ItemCube1);
ItemCube1.addIngredient(Material.ENDER_CHEST);
ItemCube1.addIngredient(Material.NETHER_STAR);
Bukkit.addRecipe(ItemCube1);
} }
public static void Initialize_ArrowQuiver_Recipe() { public static void Initialize_ArrowQuiver_Recipe() {
ItemStack arrow_quiver = new ItemStack(Material.TIPPED_ARROW); ItemStack arrow_quiver = new ItemStack(Material.TIPPED_ARROW);

View File

@ -127,6 +127,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.ArtifactItem;
import sig.plugin.TwosideKeeper.HelperStructures.ArtifactItemType; import sig.plugin.TwosideKeeper.HelperStructures.ArtifactItemType;
import sig.plugin.TwosideKeeper.HelperStructures.CubeType; import sig.plugin.TwosideKeeper.HelperStructures.CubeType;
import sig.plugin.TwosideKeeper.HelperStructures.DeathStructure; import sig.plugin.TwosideKeeper.HelperStructures.DeathStructure;
import sig.plugin.TwosideKeeper.HelperStructures.ItemCube;
import sig.plugin.TwosideKeeper.HelperStructures.ItemRarity; import sig.plugin.TwosideKeeper.HelperStructures.ItemRarity;
import sig.plugin.TwosideKeeper.HelperStructures.MalleableBaseQuest; import sig.plugin.TwosideKeeper.HelperStructures.MalleableBaseQuest;
import sig.plugin.TwosideKeeper.HelperStructures.MonsterDifficulty; import sig.plugin.TwosideKeeper.HelperStructures.MonsterDifficulty;
@ -1260,13 +1261,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
if (ev.getMessage().equalsIgnoreCase("()") || ev.getMessage().indexOf(" ()")>-1 || (ev.getMessage().indexOf("() ")>-1 && ev.getMessage().indexOf("() ")==0)) { if (ev.getMessage().equalsIgnoreCase("()") || ev.getMessage().indexOf(" ()")>-1 || (ev.getMessage().indexOf("() ")>-1 && ev.getMessage().indexOf("() ")==0)) {
ev.setMessage(ev.getMessage().replace("()", "("+ev.getPlayer().getLocation().getBlockX()+","+ev.getPlayer().getLocation().getBlockY()+","+ev.getPlayer().getLocation().getBlockZ()+")")); ev.setMessage(ev.getMessage().replace("()", "("+ev.getPlayer().getLocation().getBlockX()+","+ev.getPlayer().getLocation().getBlockY()+","+ev.getPlayer().getLocation().getBlockZ()+")"));
} }
for (int i=0;i<Bukkit.getOnlinePlayers().toArray().length;i++) { playMessageNotification(ev.getPlayer());
Player p = (Player)Bukkit.getOnlinePlayers().toArray()[i];
PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId());
if (pd.sounds_enabled) {
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BASEDRUM, 0.6f, 0.85f);
}
}
int pos = -1; int pos = -1;
log(ev.getMessage()+" "+ev.getMessage().indexOf(" []"),5); log(ev.getMessage()+" "+ev.getMessage().indexOf(" []"),5);
if (ev.getMessage().equalsIgnoreCase("[]") || ev.getMessage().indexOf(" []")>-1 || (ev.getMessage().indexOf("[] ")>-1 && ev.getMessage().indexOf("[] ")==0)) { if (ev.getMessage().equalsIgnoreCase("[]") || ev.getMessage().indexOf(" []")>-1 || (ev.getMessage().indexOf("[] ")>-1 && ev.getMessage().indexOf("[] ")==0)) {
@ -1282,6 +1277,16 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
public static void playMessageNotification(Player player) {
for (int i=0;i<Bukkit.getOnlinePlayers().toArray().length;i++) {
Player p = (Player)Bukkit.getOnlinePlayers().toArray()[i];
PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId());
if (pd.sounds_enabled) {
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BASEDRUM, 0.6f, 0.85f);
}
}
}
@EventHandler(priority=EventPriority.LOW) @EventHandler(priority=EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent ev) { public void onPlayerInteract(PlayerInteractEvent ev) {
Block b = ev.getClickedBlock(); Block b = ev.getClickedBlock();
@ -1419,8 +1424,12 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else { } else {
size=27; size=27;
} }
if (!ItemCube.isSomeoneViewingItemCube(itemcube_id,ev.getPlayer())) {
ev.getPlayer().openInventory(Bukkit.getServer().createInventory(ev.getPlayer(), size, "Item Cube #"+itemcube_id)); ev.getPlayer().openInventory(Bukkit.getServer().createInventory(ev.getPlayer(), size, "Item Cube #"+itemcube_id));
ev.getPlayer().playSound(ev.getPlayer().getLocation(), Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f); ev.getPlayer().playSound(ev.getPlayer().getLocation(), Sound.BLOCK_CHEST_OPEN, 1.0f, 1.0f);
} else {
ItemCube.displayErrorMessage(ev.getPlayer());
}
} }
} }
if (b!=null && (b.getType() == Material.SIGN || if (b!=null && (b.getType() == Material.SIGN ||
@ -1699,22 +1708,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
Player p = (Player)(Bukkit.getPlayer(ev.getWhoClicked().getName())); Player p = (Player)(Bukkit.getPlayer(ev.getWhoClicked().getName()));
p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_USE, 1.0f, 1.0f); p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_USE, 1.0f, 1.0f);
} }
//Item cube should be in slot 4.
if (ev.getInventory().getItem(5)!=null) {
ItemMeta inventory_itemMeta=ev.getInventory().getItem(5).getItemMeta();
if (inventory_itemMeta.hasLore() && inventory_itemMeta.getLore().size()==4) {
log("4 Elements detected.",5);
String loreitem = inventory_itemMeta.getLore().get(3);
log("Lore data is: "+loreitem,5);
if (loreitem!=null && loreitem.contains(ChatColor.DARK_PURPLE+"ID#")) {
log("This is an Item Cube. Invalidate recipe.",4);
//This is an item cube. Invalidate the recipe.
ev.getInventory().getItem(0).setType(Material.AIR);
ev.getWhoClicked().sendMessage(ChatColor.RED+"You cannot craft items with an Item Cube!");
ev.setCurrentItem(new ItemStack(Material.AIR));
}
}
}
if (ev.getCurrentItem().hasItemMeta()) { if (ev.getCurrentItem().hasItemMeta()) {
ItemMeta item_meta = ev.getCurrentItem().getItemMeta(); ItemMeta item_meta = ev.getCurrentItem().getItemMeta();
if (item_meta.getDisplayName()!=null && if (item_meta.getDisplayName()!=null &&
@ -1879,13 +1872,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ev.getOldCursor().getEnchantmentLevel(Enchantment.ARROW_INFINITE)==5) { ev.getOldCursor().getEnchantmentLevel(Enchantment.ARROW_INFINITE)==5) {
ev.setCancelled(true); ev.setCancelled(true);
} }
if (ev.getInventory().getTitle().contains("Item Cube #")) {
log("Item Cube window identified.",5);
final int id=Integer.parseInt(ev.getInventory().getTitle().split("#")[1]);
if (itemCube_getCubeType(id)==CubeType.ENDER) {
ev.setCancelled(true);
}
}
} }
@EventHandler(priority=EventPriority.LOW) @EventHandler(priority=EventPriority.LOW)
@ -2069,6 +2055,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
log("Item Cube window identified.",5); log("Item Cube window identified.",5);
final int id=Integer.parseInt(ev.getInventory().getTitle().split("#")[1]); final int id=Integer.parseInt(ev.getInventory().getTitle().split("#")[1]);
//Check to see if the cursor item is an item cube. //Check to see if the cursor item is an item cube.
/* OLD ITEM CUBE DUPLICATION CHECK
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -2097,6 +2084,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
}},1); }},1);
*/
/*//OLD ENDER ITEM CUBE CODE.
if (itemCube_getCubeType(id)==CubeType.ENDER) { if (itemCube_getCubeType(id)==CubeType.ENDER) {
log("Ender Item Cube verified.",4); log("Ender Item Cube verified.",4);
//We are going to look at all players and see if they have this inventory open. //We are going to look at all players and see if they have this inventory open.
@ -2131,8 +2120,50 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
},10); },10);
} }
} }
}*/
}
if ((ev.getInventory().getType()!=InventoryType.WORKBENCH ||
(ev.getInventory().getType()==InventoryType.WORKBENCH && ev.getRawSlot()>9)) && ev.getCurrentItem()!=null) {
if (ev.getCurrentItem().hasItemMeta() && (ev.getCurrentItem().getType()!=Material.AIR)) {
ItemMeta item_meta = ev.getCurrentItem().getItemMeta();
if (item_meta.hasLore()) {
List<String> item_meta_lore = item_meta.getLore();
if (item_meta_lore.size()==4 && item_meta_lore.get(3).contains(ChatColor.DARK_PURPLE+"ID#")) {
int idnumb = Integer.parseInt(item_meta_lore.get(3).split("#")[1]);
int itemcubeid = -1;
if (ev.getWhoClicked().getOpenInventory().getTitle().contains("Item Cube #")) {
itemcubeid = Integer.parseInt(ev.getWhoClicked().getOpenInventory().getTitle().split("#")[1]); //This is the ID of the window we are looking at, if one exists.
} else {
itemcubeid = -1;
}
CubeType cubetype = CubeType.NORMAL;
//This is an Item Cube.
//Check to see if the cursor item is an item cube.
if ((ev.getCurrentItem().getType()==Material.CHEST ||
ev.getCurrentItem().getType()==Material.STORAGE_MINECART ||
ev.getCurrentItem().getType()==Material.ENDER_CHEST) &&
ev.getCurrentItem().hasItemMeta() &&
ev.getCurrentItem().getItemMeta().hasLore()) {
log("The clicked item has lore...",5);
for (int i=0;i<ev.getCurrentItem().getItemMeta().getLore().size();i++) {
if (ev.getCurrentItem().getItemMeta().getLore().get(i).contains(ChatColor.DARK_PURPLE+"ID#")) {
log("We clicked an item cube, checking ID.",5);
//We clicked an item cube. Check its ID.
int clicked_id = Integer.parseInt(ev.getCurrentItem().getItemMeta().getLore().get(i).split("#")[1]);
log("ID is "+clicked_id+" and we are viewing "+itemcubeid,5);
if (clicked_id==itemcubeid) {
//The inventory we are viewing is the same as the item cube we have clicked on!
//Stop this before the player does something dumb!
//Player p = ((Player)ev.getWhoClicked());
//p.playSound(p.getLocation(), Sound.BLOCK_NOTE_HARP, 0.4f, 0.2f);
ev.setCancelled(true);
break;
} }
} }
}
}
}}}}
//WARNING! This only happens for ITEM CUBES! Do not add other items in here! //WARNING! This only happens for ITEM CUBES! Do not add other items in here!
if ((ev.getInventory().getType()!=InventoryType.WORKBENCH || if ((ev.getInventory().getType()!=InventoryType.WORKBENCH ||
@ -2168,32 +2199,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
itemcubeid=Integer.parseInt(ev.getInventory().getTitle().split("#")[1]); itemcubeid=Integer.parseInt(ev.getInventory().getTitle().split("#")[1]);
} }
//Check to see if the cursor item is an item cube.
if ((ev.getCursor().getType()==Material.CHEST ||
ev.getCursor().getType()==Material.STORAGE_MINECART ||
ev.getCursor().getType()==Material.ENDER_CHEST) &&
ev.getCursor().hasItemMeta() &&
ev.getCursor().getItemMeta().hasLore()) {
log("The clicked item has lore...",5);
for (int i=0;i<ev.getCursor().getItemMeta().getLore().size();i++) {
if (ev.getCursor().getItemMeta().getLore().get(i).contains(ChatColor.DARK_PURPLE+"ID#")) {
log("We clicked an item cube, checking ID.",5);
//We clicked an item cube. Check its ID.
int clicked_id = Integer.parseInt(ev.getCursor().getItemMeta().getLore().get(i).split("#")[1]);
log("ID is "+clicked_id+" and we are viewing "+itemcubeid,5);
if (clicked_id==itemcubeid) {
//The inventory we are viewing is the same as the item cube we have clicked on!
//Stop this before the player does something dumb!
ev.setCancelled(true);
break;
}
}
}
}
/* OLD ENDER ITEM CUBE CODE
if (itemCube_getCubeType(idnumb)==CubeType.ENDER) { if (itemCube_getCubeType(idnumb)==CubeType.ENDER) {
log("This is an Ender Item Cube transfer click.",5); log("This is an Ender Item Cube transfer click.",5);
//We are going to look at all players and see if they have this inventory open. //We are going to look at all players and see if they have this inventory open.
@ -2213,9 +2221,18 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
},10); },10);
} }
} }
} }*/
//Check if cursor is similar.
if (ev.getCursor().isSimilar(ev.getCurrentItem()) &&
cubetype==CubeType.ENDER) {
//Don't allow it.
ev.setCancelled(true);
ev.setCursor(ev.getCurrentItem());
}
else
//Make sure we are not already inside the cube we're placing into. //Make sure we are not already inside the cube we're placing into.
if (!ItemCube.isSomeoneViewingItemCube(idnumb,(Player)ev.getWhoClicked())) {
if (idnumb!=itemcubeid) { if (idnumb!=itemcubeid) {
log(idnumb+" does not match "+itemcubeid,5); log(idnumb+" does not match "+itemcubeid,5);
//Try to insert item inside this item cube. //Try to insert item inside this item cube.
@ -2238,7 +2255,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
final int ider = idnumb; final int ider = idnumb;
final List<ItemStack> items = virtual_inventory; final List<ItemStack> items = virtual_inventory;
final CubeType type = cubetype; final CubeType type = cubetype;
/*//OLD ENDER ITEM CUBE CODE.
if (itemCube_getCubeType(idnumb)==CubeType.ENDER) { if (itemCube_getCubeType(idnumb)==CubeType.ENDER) {
log("This is an Ender Item Cube transfer click.",5); log("This is an Ender Item Cube transfer click.",5);
//We are going to look at all players and see if they have this inventory open. //We are going to look at all players and see if they have this inventory open.
@ -2260,9 +2277,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
itemCube_saveConfig(ider,items,type); itemCube_saveConfig(ider,items,type);
} }
},2); },2);
} else { } else {*/
itemCube_saveConfig(ider,items,type); itemCube_saveConfig(ider,items,type);
} //}
ev.setCursor(new ItemStack(Material.AIR)); ev.setCursor(new ItemStack(Material.AIR));
break; break;
} else { } else {
@ -2296,7 +2313,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
final List<ItemStack> items = virtual_inventory; final List<ItemStack> items = virtual_inventory;
final CubeType type = cubetype; final CubeType type = cubetype;
if (itemCube_getCubeType(idnumb)==CubeType.ENDER) { /*//OLD ENDER ITEM CUBE CODE
* if (itemCube_getCubeType(idnumb)==CubeType.ENDER) {
log("This is an Ender Item Cube transfer click.",5); log("This is an Ender Item Cube transfer click.",5);
//We are going to look at all players and see if they have this inventory open. //We are going to look at all players and see if they have this inventory open.
final int id = idnumb; final int id = idnumb;
@ -2318,9 +2336,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
},2); },2);
break; break;
} else { } else {*/
itemCube_saveConfig(ider,items,type); itemCube_saveConfig(ider,items,type);
} //}
} }
} }
} }
@ -2353,6 +2371,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
final int ider = idnumb; final int ider = idnumb;
final List<ItemStack> items = itemlist; final List<ItemStack> items = itemlist;
final CubeType type = cubetype; final CubeType type = cubetype;
/* OLD ENDER ITEM CUBE CODE.
if (itemCube_getCubeType(idnumb)==CubeType.ENDER) { if (itemCube_getCubeType(idnumb)==CubeType.ENDER) {
log("This is an Ender Item Cube transfer click.",5); log("This is an Ender Item Cube transfer click.",5);
//We are going to look at all players and see if they have this inventory open. //We are going to look at all players and see if they have this inventory open.
@ -2376,7 +2395,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
},2); },2);
} else { } else {
itemCube_saveConfig(ider,items,type); itemCube_saveConfig(ider,items,type);
} }*/
ev.setCursor(new ItemStack(Material.AIR)); ev.setCursor(new ItemStack(Material.AIR));
break; break;
} else { } else {
@ -2388,6 +2407,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
for (int j=0;j<ev.getView().getTopInventory().getSize();j++) { for (int j=0;j<ev.getView().getTopInventory().getSize();j++) {
itemlist.add(ev.getView().getTopInventory().getItem(j)); itemlist.add(ev.getView().getTopInventory().getItem(j));
} }
/* OLD ENDER ITEM CUBE CODE
if (itemCube_getCubeType(idnumb)==CubeType.ENDER) { if (itemCube_getCubeType(idnumb)==CubeType.ENDER) {
log("This is an Ender Item Cube transfer click.",5); log("This is an Ender Item Cube transfer click.",5);
//We are going to look at all players and see if they have this inventory open. //We are going to look at all players and see if they have this inventory open.
@ -2412,7 +2432,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
itemCube_saveConfig(ider,items,type); itemCube_saveConfig(ider,items,type);
} }
},2); },2);
} }*/
} }
} }
} }
@ -2436,6 +2456,11 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
} }
} else {
ev.setCancelled(true);
ev.setCursor(ev.getCursor());
ItemCube.displayErrorMessage((Player)ev.getWhoClicked());
}
} }
} }
} }
@ -2466,17 +2491,24 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
Player p = (Player)viewers.get(i); Player p = (Player)viewers.get(i);
//We're going to check if the currently opened inventory is not an ender item cube. Otherwise we cannot proceed. //We're going to check if the currently opened inventory is not an ender item cube. Otherwise we cannot proceed.
if (p.getOpenInventory().getTitle().contains("Item Cube #") && /*//OLD ENDER ITEM CUBE CHECK CODE.
* if (p.getOpenInventory().getTitle().contains("Item Cube #") &&
itemCube_getCubeType(Integer.parseInt(p.getOpenInventory().getTitle().split("#")[1]))==CubeType.ENDER && itemCube_getCubeType(Integer.parseInt(p.getOpenInventory().getTitle().split("#")[1]))==CubeType.ENDER &&
ev.getRawSlot()<27) { ev.getRawSlot()<27) {
p.sendMessage("Cannot access another item cube due to being inside an ender item cube."); p.sendMessage("Cannot access another item cube due to being inside an ender item cube.");
//p.openInventory(Bukkit.getServer().createInventory(p, inventory_size, "Item Cube #"+Integer.parseInt(p.getOpenInventory().getTitle().split("#")[1]))); //p.openInventory(Bukkit.getServer().createInventory(p, inventory_size, "Item Cube #"+Integer.parseInt(p.getOpenInventory().getTitle().split("#")[1])));
} else { } else {*/
if (!ItemCube.isSomeoneViewingItemCube(idnumb,p)) {
ev.setCancelled(true); ev.setCancelled(true);
ev.setResult(Result.DENY); ev.setResult(Result.DENY);
p.openInventory(Bukkit.getServer().createInventory(p, inventory_size, "Item Cube #"+idnumb)); p.openInventory(Bukkit.getServer().createInventory(p, inventory_size, "Item Cube #"+idnumb));
p.playSound(p.getLocation(),Sound.BLOCK_CHEST_OPEN,1.0f,1.0f); p.playSound(p.getLocation(),Sound.BLOCK_CHEST_OPEN,1.0f,1.0f);
} else {
ev.setCancelled(true);
ev.setResult(Result.DENY);
ItemCube.displayErrorMessage(p);
} }
//}
} }
} }
} }
@ -3997,6 +4029,50 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
result.setAmount(result.getAmount()*5); //TNT recipes are 5 times as effective. result.setAmount(result.getAmount()*5); //TNT recipes are 5 times as effective.
} }
//Check if we are using an item cube in a non-item cube recipe.
//Item cube should be in slot 4.
if (ev.getInventory().getItem(5)!=null) {
ItemMeta inventory_itemMeta=ev.getInventory().getItem(5).getItemMeta();
if (inventory_itemMeta.hasLore() && inventory_itemMeta.getLore().size()==4) {
log("4 Elements detected.",5);
String loreitem = inventory_itemMeta.getLore().get(3);
log("Lore data is: "+loreitem,5);
if (loreitem!=null && loreitem.contains(ChatColor.DARK_PURPLE+"ID#")) {
log("This is an Item Cube. Invalidate recipe.",4);
//This is an item cube. Invalidate the recipe.
ev.getInventory().setResult(new ItemStack(Material.AIR));
//ev.getWhoClicked().sendMessage(ChatColor.RED+"You cannot craft items with an Item Cube!");
//ev.setCurrentItem(new ItemStack(Material.AIR));
}
}
}
//This could be our duplication recipe...
int itemcount=0;
ItemStack newitem = null;
for (int i=1;i<10;i++) {
if (ev.getInventory().getItem(i)!=null &&
ev.getInventory().getItem(i).getType()!=Material.AIR) {
ItemMeta inventory_itemMeta1=ev.getInventory().getItem(i).getItemMeta();
if (inventory_itemMeta1.hasLore() && inventory_itemMeta1.getLore().size()==4) {
log("4 Elements detected.",5);
String loreitem = inventory_itemMeta1.getLore().get(3);
log("Lore data is: "+loreitem,5);
if (loreitem!=null && loreitem.contains(ChatColor.DARK_PURPLE+"ID#")) {
//log("This is an Item Cube. Invalidate recipe.",4);
//Now set the result to this item cube!
newitem = ev.getInventory().getItem(i).clone();
newitem.setAmount(2);
}
}
itemcount++;
}
}
if (itemcount==2) {
//This is the correct recipe. Touch the result.
ev.getInventory().setResult(newitem);
}
//Look for the base material. //Look for the base material.
if (Artifact.isArtifact(ev.getInventory().getResult()) && result.getType()!=Material.STAINED_GLASS_PANE && GenericFunctions.isEquip(result)) { if (Artifact.isArtifact(ev.getInventory().getResult()) && result.getType()!=Material.STAINED_GLASS_PANE && GenericFunctions.isEquip(result)) {
@ -4200,21 +4276,21 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} else } else
if (items_found.get(0).getEnchantmentLevel(Enchantment.LUCK)==2) { if (items_found.get(0).getEnchantmentLevel(Enchantment.LUCK)==2) {
//This produces Artifact Essence. //This produces Artifact Essence.
ItemStack newitem = Artifact.createArtifactItem(ArtifactItem.valueOf("ARTIFACT_"+mat_suffix)); ItemStack newitem1 = Artifact.createArtifactItem(ArtifactItem.valueOf("ARTIFACT_"+mat_suffix));
newitem.setAmount(2); newitem1.setAmount(2);
ev.getInventory().setResult(newitem); ev.getInventory().setResult(newitem1);
} else } else
if (items_found.get(0).getEnchantmentLevel(Enchantment.LUCK)==3) { if (items_found.get(0).getEnchantmentLevel(Enchantment.LUCK)==3) {
//This produces Ancient Essence. //This produces Ancient Essence.
ItemStack newitem = Artifact.createArtifactItem(ArtifactItem.valueOf("ANCIENT_"+mat_suffix)); ItemStack newitem1 = Artifact.createArtifactItem(ArtifactItem.valueOf("ANCIENT_"+mat_suffix));
newitem.setAmount(2); newitem1.setAmount(2);
ev.getInventory().setResult(newitem); ev.getInventory().setResult(newitem1);
} else } else
if (items_found.get(0).getEnchantmentLevel(Enchantment.LUCK)==4) { if (items_found.get(0).getEnchantmentLevel(Enchantment.LUCK)==4) {
//This produces Lost Essence. //This produces Lost Essence.
ItemStack newitem = Artifact.createArtifactItem(ArtifactItem.valueOf("LOST_"+mat_suffix)); ItemStack newitem1 = Artifact.createArtifactItem(ArtifactItem.valueOf("LOST_"+mat_suffix));
newitem.setAmount(2); newitem1.setAmount(2);
ev.getInventory().setResult(newitem); ev.getInventory().setResult(newitem1);
} }
} }
} }
@ -4239,17 +4315,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
//log("This is tier "+tier+". Enchantment level of "+ev.getInventory().getItem(slot_found).toString(),2); //log("This is tier "+tier+". Enchantment level of "+ev.getInventory().getItem(slot_found).toString(),2);
//Decompose this into a higher tier of the next item. //Decompose this into a higher tier of the next item.
if (tier<10) { if (tier<10) {
ItemStack newitem = Artifact.convert(new ItemStack(Material.STAINED_GLASS_PANE,1,(short)ArtifactItemType.valueOf(Artifact.returnRawTool(ev.getInventory().getItem(slot_found).getType())).getDataValue())); ItemStack newitem1 = Artifact.convert(new ItemStack(Material.STAINED_GLASS_PANE,1,(short)ArtifactItemType.valueOf(Artifact.returnRawTool(ev.getInventory().getItem(slot_found).getType())).getDataValue()));
ItemMeta m = newitem.getItemMeta(); ItemMeta m = newitem1.getItemMeta();
List<String> lore = m.getLore(); List<String> lore = m.getLore();
lore.add(0,ChatColor.GOLD+""+ChatColor.BOLD+"T"+(tier+1)+" Crafting Recipe"); lore.add(0,ChatColor.GOLD+""+ChatColor.BOLD+"T"+(tier+1)+" Crafting Recipe");
//lore.add(1,ChatColor.GOLD+""+ChatColor.BOLD+"T"+tier+ChatColor.RESET+ChatColor.GOLD+" "+GenericFunctions.CapitalizeFirstLetters(item.getItemName())+" Recipe"); //lore.add(1,ChatColor.GOLD+""+ChatColor.BOLD+"T"+tier+ChatColor.RESET+ChatColor.GOLD+" "+GenericFunctions.CapitalizeFirstLetters(item.getItemName())+" Recipe");
m.setLore(lore); m.setLore(lore);
m.setDisplayName(ChatColor.GOLD+""+ChatColor.BOLD+"T"+(tier+1)+" Artifact "+GenericFunctions.CapitalizeFirstLetters(Artifact.returnRawTool(ev.getInventory().getItem(slot_found).getType()))+" Recipe"); m.setDisplayName(ChatColor.GOLD+""+ChatColor.BOLD+"T"+(tier+1)+" Artifact "+GenericFunctions.CapitalizeFirstLetters(Artifact.returnRawTool(ev.getInventory().getItem(slot_found).getType()))+" Recipe");
newitem.setItemMeta(m); newitem1.setItemMeta(m);
newitem.addUnsafeEnchantment(Enchantment.LUCK, tier+1); newitem1.addUnsafeEnchantment(Enchantment.LUCK, tier+1);
ev.getInventory().setResult(newitem); ev.getInventory().setResult(newitem1);
} }
} }
} }
@ -4894,10 +4970,10 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
p.setMaxHealth(hp); p.setMaxHealth(hp);
p.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(hp);
if (!p.isDead()) { if (!p.isDead()) {
p.setHealth(p.getHealth()); p.setHealth(p.getHealth());
} }
p.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(hp);
} }

View File

@ -97,6 +97,11 @@ public final class TwosideKeeperAPI {
return TwosideKeeper.CalculateDamageReduction(dmg_amt, p, p); return TwosideKeeper.CalculateDamageReduction(dmg_amt, p, p);
} }
//Spleef COMMANDS.
public static void playMessageNotification(Player sender) {
TwosideKeeper.playMessageNotification(sender);
}
//Spleef COMMANDS. //Spleef COMMANDS.
public static boolean isPlayingSpleef(Player p) { public static boolean isPlayingSpleef(Player p) {
return SpleefManager.playerIsPlayingSpleef(p); return SpleefManager.playerIsPlayingSpleef(p);