furniture/src/de/Ste3et_C0st/Furniture/Objects/electric/camera.java

115 lines
3.8 KiB
Java
Raw Normal View History

2015-04-28 01:39:37 +02:00
package de.Ste3et_C0st.Furniture.Objects.electric;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.map.MapView;
import de.Ste3et_C0st.Furniture.Camera.Utils.RenderClass;
2017-04-06 14:52:27 +02:00
import de.Ste3et_C0st.Furniture.Camera.Utils.RenderClass.ScaleMode;
2015-11-18 18:04:31 +01:00
import de.Ste3et_C0st.Furniture.Main.main;
2017-04-06 14:52:27 +02:00
import de.Ste3et_C0st.FurnitureLib.ShematicLoader.Events.ProjectClickEvent;
2018-11-25 17:59:55 +01:00
import de.Ste3et_C0st.FurnitureLib.Utilitis.Relative;
2017-04-06 14:52:27 +02:00
import de.Ste3et_C0st.FurnitureLib.main.FurnitureHelper;
2015-07-08 18:15:57 +02:00
import de.Ste3et_C0st.FurnitureLib.main.ObjectID;
2017-04-06 14:52:27 +02:00
import de.Ste3et_C0st.FurnitureLib.main.entity.fEntity;
2015-04-28 01:39:37 +02:00
2017-04-06 14:52:27 +02:00
public class camera extends FurnitureHelper implements Listener{
private fEntity entity = null, entity2 = null;
private String zoom = "#ZOOM0#";
private ScaleMode mode = ScaleMode.NORMAL;
2015-11-18 18:04:31 +01:00
public camera(ObjectID id){
super(id);
2017-04-06 14:52:27 +02:00
Bukkit.getPluginManager().registerEvents(this, main.instance);
2015-07-08 18:15:57 +02:00
2017-04-06 14:52:27 +02:00
boolean b = false;
for(fEntity stand : id.getPacketList()){
if(stand.getCustomName().startsWith("#ZOOM")){
if(stand.isCustomNameVisible()){
stand.setNameVasibility(false);
b = true;
}
this.entity2 = stand;
zoom = stand.getCustomName();
}
if(stand.getItemInMainHand() != null){
if(stand.getItemInMainHand().getType().equals(Material.TRIPWIRE_HOOK)){
this.entity = stand;
}
}
}
2015-07-08 18:15:57 +02:00
2017-04-06 14:52:27 +02:00
if(b){
update();
2015-07-08 18:15:57 +02:00
}
2015-08-13 19:26:30 +02:00
}
2017-04-06 14:52:27 +02:00
public void setZoom(){
if(entity == null){return;}
Relative r = new Relative(getCenter(), -0.07, 0.0625, -0.13, getBlockFace().getOppositeFace());
Location loc = r.getSecondLocation();
if(zoom.equalsIgnoreCase("#ZOOM1#")){
loc = r.getSecondLocation().subtract(0, .15, 0);
}else if(zoom.equalsIgnoreCase("#ZOOM2#")){
loc = r.getSecondLocation().subtract(0, .3, 0);
}else if(zoom.equalsIgnoreCase("#ZOOM3#")){
loc = r.getSecondLocation().subtract(0, .4, 0);
}
loc.setYaw(entity.getLocation().getYaw());
this.entity.teleport(loc);
update();
2015-04-28 01:39:37 +02:00
}
2015-08-17 22:27:16 +02:00
2015-04-28 01:39:37 +02:00
@SuppressWarnings("deprecation")
2015-07-08 18:15:57 +02:00
@EventHandler
2017-04-06 14:52:27 +02:00
public void onFurnitureClick(ProjectClickEvent e) {
if(!e.getID().equals(getObjID())){return;}
2015-07-08 18:15:57 +02:00
Player p = e.getPlayer();
Location pLocation = getLutil().getRelativ(p.getLocation().getBlock().getLocation(), getBlockFace(), -1D, 0D).clone();
2015-08-17 22:27:16 +02:00
Location locCopy = getLocation().getBlock().getLocation().clone();
pLocation.setYaw(locCopy.getYaw());
if(pLocation.equals(locCopy)){
if(getLutil().yawToFace(p.getLocation().getYaw()).getOppositeFace().equals(getBlockFace())){
2017-04-06 14:52:27 +02:00
if(e.canBuild()){
2018-11-25 17:59:55 +01:00
if(!p.getInventory().getItemInMainHand().getType().equals(Material.FILLED_MAP)){
2017-04-06 14:52:27 +02:00
if(entity == null || entity2 == null)return;
if(this.zoom.equalsIgnoreCase("#ZOOM0#")){
this.mode = ScaleMode.FAR;
this.zoom = "#ZOOM1#";
}else if(this.zoom.equalsIgnoreCase("#ZOOM1#")){
this.mode = ScaleMode.FAHRTEST;
this.zoom = "#ZOOM2#";
}else if(this.zoom.equalsIgnoreCase("#ZOOM2#")){
this.mode = ScaleMode.COMPLETE;
this.zoom = "#ZOOM3#";
}else if(this.zoom.equalsIgnoreCase("#ZOOM3#")){
this.mode = ScaleMode.NORMAL;
this.zoom = "#ZOOM0#";
}
this.entity2.setName(zoom);
setZoom();
update();
return;
}
}else{
if(!p.getInventory().getItemInMainHand().getType().equals(Material.MAP)){
return;
}
}
MapView view = Bukkit.getMap(p.getInventory().getItemInMainHand().getDurability());
Location l = getLocation().clone();
l.setYaw(getLutil().FaceToYaw(getBlockFace().getOppositeFace()));
2017-04-06 14:52:27 +02:00
view.getRenderers().clear();
2017-10-28 18:54:21 +02:00
try{view.addRenderer(new RenderClass(l, mode));}catch (Exception ex){ex.printStackTrace();}
2015-08-17 22:27:16 +02:00
}
2015-04-28 01:39:37 +02:00
}
}
}