From 4770e672b060496e8b27786d3ae05512bba5eca7 Mon Sep 17 00:00:00 2001 From: BerndiVader Date: Fri, 27 Sep 2019 21:28:14 +0200 Subject: [PATCH] added holding placeholder for caster, trigger & target added excludeslots to openbackbag --- gradle.properties | 4 --- .../gmail/berndivader/mythicmobsext/Main.java | 1 - .../mythicmobsext/backbags/BackBag.java | 21 +++++++++++-- .../backbags/mechanics/OpenBackBag.java | 21 +++++++++++-- .../placeholders/PlaceholderRegistery.java | 31 +++++++++++++++++++ .../mythicmobsext/utils/Utils.java | 3 +- 6 files changed, 70 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9fcfd65c..e69de29b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +0,0 @@ -#Fri Sep 27 19:02:43 CEST 2019 -appName=MythicMobsExtension -artbuild=3832 -artver=1.440-SNAPSHOT diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/Main.java b/src/main/java/com/gmail/berndivader/mythicmobsext/Main.java index d706b39d..9f63a18e 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/Main.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/Main.java @@ -161,7 +161,6 @@ public void onDisable() { CachedOwnerHandler.cleanUp(); CachedOwnerHandler.saveCachedOwners(); } - BackBagHelper.saveBags(); Main.mythicplayers = null; Main.cachedOwnerHandler = null; pluginmanager.disablePlugin(this); diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/backbags/BackBag.java b/src/main/java/com/gmail/berndivader/mythicmobsext/backbags/BackBag.java index be62af52..7eb07b26 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/backbags/BackBag.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/backbags/BackBag.java @@ -1,5 +1,7 @@ package com.gmail.berndivader.mythicmobsext.backbags; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import org.bukkit.Bukkit; @@ -43,6 +45,7 @@ private int size; String name; boolean only_view; + Listexcludes_slots; public BackBag(Entity onwer) { this(onwer,9); @@ -63,8 +66,13 @@ public BackBag(Entity owner,int size,ItemStack[]default_content) { public BackBag(Entity owner,int size,ItemStack[]default_content,String name,boolean temporary) { this(owner,size,default_content,name,temporary,false); } - + public BackBag(Entity owner,int size,ItemStack[]default_content,String name,boolean temporary,boolean override) { + this(owner,size,default_content,name,temporary,override,new ArrayList<>()); + } + + + public BackBag(Entity owner,int size,ItemStack[]default_content,String name,boolean temporary,boolean override,Listexcluded_slots) { if(name==null) name=BackBagHelper.str_name; size=size%9>0?size+(9-size%9):size; this.owner=owner; @@ -74,20 +82,27 @@ public BackBag(Entity owner,int size,ItemStack[]default_content,String name,bool } this.size=inventory.getSize(); if(default_content!=null&&default_content.length<=this.size) inventory.setContents(default_content); + this.excludes_slots=excluded_slots; } public void viewBackBag(Player player) { - viewBackBag(player,false); + viewBackBag(player,this.only_view,this.excludes_slots); } public void viewBackBag(Player player,boolean bool) { + viewBackBag(player,bool,this.excludes_slots); + } + + public void viewBackBag(Player player,boolean bool,List excludes_slots) { this.only_view=bool; + this.excludes_slots=excludes_slots; Main.pluginmanager.registerEvents(this,Main.getPlugin()); this.viewer=player; player.openInventory(inventory); } + public boolean isPresent() { return this.inventory!=null; } @@ -136,7 +151,7 @@ public void inventoryOpen(InventoryOpenEvent e) { @EventHandler public void interact(InventoryClickEvent e) { if(e.getWhoClicked()==viewer) { - if(only_view) e.setCancelled(true); + if(only_view&&!excludes_slots.contains(e.getRawSlot())) e.setCancelled(true); if(e.getClickedInventory()!=null&&e.getView().getTitle().equals(this.name)) { owner.setMetadata(Utils.meta_LASTCLICKEDSLOT,new FixedMetadataValue(Main.getPlugin(),e.getSlot())); owner.setMetadata(Utils.meta_LASTCLICKEDBAG,new FixedMetadataValue(Main.getPlugin(),this.name)); diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/backbags/mechanics/OpenBackBag.java b/src/main/java/com/gmail/berndivader/mythicmobsext/backbags/mechanics/OpenBackBag.java index f942718a..691f025e 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/backbags/mechanics/OpenBackBag.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/backbags/mechanics/OpenBackBag.java @@ -1,9 +1,13 @@ package com.gmail.berndivader.mythicmobsext.backbags.mechanics; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import com.gmail.berndivader.mythicmobsext.Main; import com.gmail.berndivader.mythicmobsext.backbags.BackBag; import com.gmail.berndivader.mythicmobsext.backbags.BackBagHelper; @@ -29,6 +33,7 @@ ItemStack[] default_items; boolean view_only,temporary; PlaceholderString bag_name; + Listexcluded_slots; public OpenBackBag(String skill, MythicLineConfig mlc) { super(skill, mlc); @@ -39,6 +44,18 @@ public OpenBackBag(String skill, MythicLineConfig mlc) { default_items=BackBagHelper.createDefaultItemStack(mlc.getString("items",null)); bag_name=mlc.getPlaceholderString(new String[] {"name","title"},"BackBag"); temporary=mlc.getBoolean("temporary",false); + String[]temp=mlc.getString("excludedslots","").split(","); + excluded_slots=new ArrayList<>(); + for(int i1=0;i1 { return Double.toString(meta.getCaster().getLocation().getZ()); })); + manager.register("caster.holding",Placeholder.meta((meta,arg)-> { + if(meta.getCaster().getEntity().isLiving()) { + LivingEntity entity=(LivingEntity)meta.getCaster().getEntity().getBukkitEntity(); + ItemStack item_stack=entity.getEquipment().getItemInMainHand(); + Material material=item_stack==null?Material.AIR:item_stack.getType(); + return material.name(); + } + return null; + })); manager.register("trigger.l.dx",Placeholder.meta((meta,arg)-> { return Double.toString(meta.getTrigger().getLocation().getX()); })); @@ -39,6 +52,15 @@ public PlaceholderRegistery() { manager.register("trigger.l.dz",Placeholder.meta((meta,arg)-> { return Double.toString(meta.getTrigger().getLocation().getZ()); })); + manager.register("trigger.holding",Placeholder.meta((meta,arg)-> { + if(meta.getTrigger().isLiving()) { + LivingEntity entity=(LivingEntity)meta.getTrigger().getBukkitEntity(); + ItemStack item_stack=entity.getEquipment().getItemInMainHand(); + Material material=item_stack==null?Material.AIR:item_stack.getType(); + return material.name(); + } + return null; + })); manager.register("target.l.dx",Placeholder.entity((entity,arg)-> { return Double.toString(entity.getLocation().getX()); })); @@ -48,6 +70,15 @@ public PlaceholderRegistery() { manager.register("target.l.dz",Placeholder.entity((entity,arg)-> { return Double.toString(entity.getLocation().getZ()); })); + manager.register("target.holding",Placeholder.entity((target,arg)-> { + if(target.isLiving()) { + LivingEntity entity=(LivingEntity)target.getBukkitEntity(); + ItemStack item_stack=entity.getEquipment().getItemInMainHand(); + Material material=item_stack==null?Material.AIR:item_stack.getType(); + return material.name(); + } + return null; + })); } diff --git a/src/main/java/com/gmail/berndivader/mythicmobsext/utils/Utils.java b/src/main/java/com/gmail/berndivader/mythicmobsext/utils/Utils.java index 965682a5..6a199b98 100644 --- a/src/main/java/com/gmail/berndivader/mythicmobsext/utils/Utils.java +++ b/src/main/java/com/gmail/berndivader/mythicmobsext/utils/Utils.java @@ -115,9 +115,10 @@ class public static final String signal_GOAL_TRAVELPOINT = "GOAL_TRAVELPOINT"; public static final String meta_DISORIENTATION = "MMEDISORIENTATION"; public static final String meta_CLICKEDSKILL="click_skill"; + public static final String meta_LASTCLICKEDBAG = "lastclickedbag"; + public static final String meta_LASTCLICKUSED = "lastclickused"; public static final String meta_LASTCLICKEDSLOT = "lastclickedslot"; public static final String signal_BACKBAGCLICK = "BAGCLICKED"; - public static final String meta_LASTCLICKEDBAG = "lastclickedbag"; public static String scripts; public static String str_PLUGINPATH; public static HashSetadvancements;