Skip to content

Commit

Permalink
added holding placeholder for caster, trigger & target
Browse files Browse the repository at this point in the history
added excludeslots to openbackbag
  • Loading branch information
BerndiVader committed Sep 27, 2019
1 parent 73931be commit 4770e67
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
4 changes: 0 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
#Fri Sep 27 19:02:43 CEST 2019
appName=MythicMobsExtension
artbuild=3832
artver=1.440-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public void onDisable() {
CachedOwnerHandler.cleanUp();
CachedOwnerHandler.saveCachedOwners();
}
BackBagHelper.saveBags();
Main.mythicplayers = null;
Main.cachedOwnerHandler = null;
pluginmanager.disablePlugin(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,6 +45,7 @@
private int size;
String name;
boolean only_view;
List<Integer>excludes_slots;

public BackBag(Entity onwer) {
this(onwer,9);
Expand All @@ -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,List<Integer>excluded_slots) {
if(name==null) name=BackBagHelper.str_name;
size=size%9>0?size+(9-size%9):size;
this.owner=owner;
Expand All @@ -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<Integer> 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;
}
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -29,6 +33,7 @@
ItemStack[] default_items;
boolean view_only,temporary;
PlaceholderString bag_name;
List<Integer>excluded_slots;

public OpenBackBag(String skill, MythicLineConfig mlc) {
super(skill, mlc);
Expand All @@ -39,14 +44,26 @@ 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<temp.length;i1++) {
try {
if(!temp[i1].isEmpty()) {
int slot=Integer.parseInt(temp[i1]);
excluded_slots.add(slot);
}
} catch (Exception ex) {
Main.logger.warning("Ignoring "+temp[i1]+" in skill "+skill+" its not a valid slot number.");
}
}
}

@Override
public boolean cast(SkillMetadata data) {
if(data.getCaster().getEntity().isPlayer()) {
Player player=(Player)data.getCaster().getEntity().getBukkitEntity();
BackBag bag=new BackBag(player,size,default_items,bag_name.get(data),temporary);
bag.viewBackBag(player);
bag.viewBackBag(player,view_only,this.excluded_slots);
return true;
}
return false;
Expand All @@ -58,7 +75,7 @@ public boolean castAtEntity(SkillMetadata data, AbstractEntity abstract_entity)
Entity holder=data.getCaster().getEntity().getBukkitEntity();
Player viewer=(Player)abstract_entity.getBukkitEntity();
BackBag bag=new BackBag(holder,size,default_items,bag_name.get(data,abstract_entity),temporary);
bag.viewBackBag(viewer,view_only);
bag.viewBackBag(viewer,view_only,this.excluded_slots);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.gmail.berndivader.mythicmobsext.placeholders;

import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;

import com.gmail.berndivader.mythicmobsext.utils.Utils;

import io.lumine.xikage.mythicmobs.skills.placeholders.Placeholder;
Expand Down Expand Up @@ -30,6 +34,15 @@ public PlaceholderRegistery() {
manager.register("caster.l.dz",Placeholder.meta((meta,arg)-> {
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());
}));
Expand All @@ -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());
}));
Expand All @@ -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;
}));


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 HashSet<Advancement>advancements;
Expand Down

0 comments on commit 4770e67

Please sign in to comment.