2015-10-31 23:50:14 +01:00
|
|
|
package de.Ste3et_C0st.Furniture.Objects.School;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.util.EulerAngle;
|
|
|
|
|
2015-11-18 18:04:31 +01:00
|
|
|
import de.Ste3et_C0st.Furniture.Main.main;
|
2015-10-31 23:50:14 +01:00
|
|
|
import de.Ste3et_C0st.FurnitureLib.Events.FurnitureBreakEvent;
|
|
|
|
import de.Ste3et_C0st.FurnitureLib.Events.FurnitureClickEvent;
|
|
|
|
import de.Ste3et_C0st.FurnitureLib.main.Furniture;
|
|
|
|
import de.Ste3et_C0st.FurnitureLib.main.ObjectID;
|
|
|
|
import de.Ste3et_C0st.FurnitureLib.main.Type.SQLAction;
|
|
|
|
import de.Ste3et_C0st.FurnitureLib.main.entity.fArmorStand;
|
|
|
|
|
|
|
|
public class TrashCan extends Furniture implements Listener {
|
|
|
|
|
2015-11-18 18:04:31 +01:00
|
|
|
public TrashCan(ObjectID id){
|
|
|
|
super(id);
|
2015-10-31 23:50:14 +01:00
|
|
|
if(isFinish()){
|
2015-11-18 18:04:31 +01:00
|
|
|
Bukkit.getPluginManager().registerEvents(this, main.getInstance());
|
2015-10-31 23:50:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
spawn(id.getStartLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onFurnitureBreak(FurnitureBreakEvent e) {
|
|
|
|
if(getObjID()==null){return;}
|
|
|
|
if(getObjID().getSQLAction().equals(SQLAction.REMOVE)){return;}
|
|
|
|
if(e.isCancelled()) return;
|
|
|
|
if(!e.getID().equals(getObjID())) return;
|
|
|
|
if(!e.canBuild()){return;}
|
|
|
|
e.remove();
|
|
|
|
delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onFurnitureClick(FurnitureClickEvent e) {
|
|
|
|
if(getObjID()==null){return;}
|
|
|
|
if(getObjID().getSQLAction().equals(SQLAction.REMOVE)){return;}
|
|
|
|
if(e.isCancelled()) return;
|
|
|
|
if(!e.getID().equals(getObjID())) return;
|
|
|
|
if(!e.canBuild()){return;}
|
2016-03-05 20:16:46 +01:00
|
|
|
ItemStack is = e.getPlayer().getInventory().getItemInMainHand();
|
2015-10-31 23:50:14 +01:00
|
|
|
fArmorStand stand = null;
|
|
|
|
for(fArmorStand s : getfAsList()){
|
|
|
|
if(s.getName().equalsIgnoreCase("#TRASH#")){
|
|
|
|
stand = s;break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(stand==null){return;}
|
|
|
|
if(is==null||is.getType()==null||is.getType().equals(Material.AIR)){
|
2016-03-05 20:16:46 +01:00
|
|
|
if(stand.getItemInMainHand()!=null&&!stand.getItemInMainHand().getType().equals(Material.AIR)){
|
|
|
|
getWorld().dropItem(getCenter(), stand.getItemInMainHand());
|
|
|
|
stand.setItemInMainHand(new ItemStack(Material.AIR));
|
2015-10-31 23:50:14 +01:00
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-03-05 20:16:46 +01:00
|
|
|
stand.setItemInMainHand(is);
|
2015-10-31 23:50:14 +01:00
|
|
|
e.getPlayer().getInventory().clear(e.getPlayer().getInventory().getHeldItemSlot());
|
|
|
|
e.getPlayer().updateInventory();
|
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void spawn(Location loc) {
|
|
|
|
List<fArmorStand> asList = new ArrayList<fArmorStand>();
|
|
|
|
Location l = getLutil().getRelativ(getCenter(), getBlockFace(), -.29, .2).add(0, -1.1, 0);
|
|
|
|
l.setYaw(getYaw());
|
|
|
|
fArmorStand stand = spawnArmorStand(getCenter().add(0, -1.2, 0));
|
|
|
|
stand.setHelmet(new ItemStack(Material.CARPET, 1,(short) 15));
|
|
|
|
stand.setSmall(true);
|
|
|
|
asList.add(stand);
|
|
|
|
|
|
|
|
float yaw = 0;
|
|
|
|
for(int i = 0; i<4;i++){
|
2016-03-19 21:36:10 +01:00
|
|
|
Location location = getLutil().getRelativ(getCenter(), getLutil().yawToFace(yaw), .43, 0);
|
|
|
|
location.add(0,-2.45,0);
|
2015-10-31 23:50:14 +01:00
|
|
|
location.setYaw(yaw);
|
|
|
|
stand = spawnArmorStand(location);
|
|
|
|
stand.setHelmet(new ItemStack(Material.IRON_FENCE));
|
|
|
|
stand.setHeadPose(getLutil().degresstoRad(new EulerAngle(10, 0, 0)));
|
|
|
|
asList.add(stand);
|
|
|
|
yaw+=90;
|
|
|
|
}
|
|
|
|
|
|
|
|
stand = spawnArmorStand(l);
|
|
|
|
stand.setSmall(true);
|
|
|
|
stand.setRightArmPose(getLutil().degresstoRad(new EulerAngle(-110,0,0)));
|
|
|
|
stand.setMarker(false);
|
|
|
|
stand.setName("#TRASH#");
|
|
|
|
asList.add(stand);
|
|
|
|
|
|
|
|
for(fArmorStand as : asList){
|
|
|
|
as.setInvisible(true);
|
|
|
|
}
|
|
|
|
send();
|
|
|
|
Bukkit.getPluginManager().registerEvents(this, getPlugin());
|
|
|
|
}
|
|
|
|
}
|