mirror of https://github.com/Ste3et/furniture.git
Add Camera Functionality for 1.9,1.10,1.11,1.12
This commit is contained in:
parent
df15c62c9f
commit
5aaa09f392
|
@ -2,27 +2,37 @@ package de.Ste3et_C0st.Furniture.Camera.Utils;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang.reflect.MethodUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import de.Ste3et_C0st.Furniture.Main.main;
|
||||
import de.Ste3et_C0st.FurnitureLib.Utilitis.Relative;
|
||||
import de.Ste3et_C0st.FurnitureLib.main.FurnitureLib;
|
||||
|
||||
public class GetBlocks {
|
||||
|
||||
//Class<?> CraftBlockClass = null;
|
||||
Class<?> CraftMagicNumbersClass = null;
|
||||
public static MinecraftBlockColor colorBlock;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> color = Class.forName("de.Ste3et_C0st.Furniture.Camera.Utils." + MinecraftBlockColor.getMainVersion() + ".BlockColor");
|
||||
if(Objects.nonNull(color)) {
|
||||
colorBlock = (MinecraftBlockColor) color.newInstance();
|
||||
}else {
|
||||
colorBlock = de.Ste3et_C0st.Furniture.Camera.Utils.v1_13.BlockColor.class.newInstance();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getBukkitVersion() {return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];}
|
||||
|
||||
public List<Layer> returnBlocks(Location startLocation, int width, int heigt, int depth, int offsetZ){
|
||||
try{
|
||||
this.CraftMagicNumbersClass = Class.forName("org.bukkit.craftbukkit."+getBukkitVersion()+".util.CraftMagicNumbers");
|
||||
|
||||
BlockFace face = main.getLocationUtil().yawToFace(startLocation.getYaw()).getOppositeFace();
|
||||
List<Layer> layerList = new ArrayList<Layer>();
|
||||
for(int i = depth; i>=0; i--){
|
||||
|
@ -46,15 +56,16 @@ public class GetBlocks {
|
|||
|
||||
public Byte getByteFromBlock(Block b){
|
||||
try {
|
||||
Object nmsBlock = CraftMagicNumbersClass.getMethod("getBlock", org.bukkit.Material.class).invoke(null, b.getType());
|
||||
Object iBlockData = nmsBlock.getClass().getMethod("getBlockData").invoke(nmsBlock);
|
||||
Object Material = MethodUtils.invokeMethod(iBlockData, "getMaterial", null);
|
||||
Object MaterialMapColor = MethodUtils.invokeMethod(Material, "i", null);
|
||||
int color = MaterialMapColor.getClass().getField("ac").getInt(MaterialMapColor) * 4;
|
||||
// if(color == 28){
|
||||
// color += randInt(0, 3);
|
||||
// }
|
||||
return (byte) color;
|
||||
return colorBlock.getBlockColor(b);
|
||||
// Object nmsBlock = CraftMagicNumbersClass.getMethod("getBlock", org.bukkit.Material.class).invoke(null, b.getType());
|
||||
// Object iBlockData = nmsBlock.getClass().getMethod("getBlockData").invoke(nmsBlock);
|
||||
// Object Material = MethodUtils.invokeMethod(iBlockData, "getMaterial", null);
|
||||
// Object MaterialMapColor = MethodUtils.invokeMethod(Material, "i", null);
|
||||
// int color = MaterialMapColor.getClass().getField("ac").getInt(MaterialMapColor) * 4;
|
||||
//// if(color == 28){
|
||||
//// color += randInt(0, 3);
|
||||
//// }
|
||||
// return (byte) color;
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
return 0;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package de.Ste3et_C0st.Furniture.Camera.Utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public abstract class MinecraftBlockColor {
|
||||
|
||||
public abstract Byte getBlockColor(Block b);
|
||||
|
||||
public static String getBukkitVersion() {return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];}
|
||||
public static String getMainVersion() {return "v1_" + getBukkitVersion().split("_")[1];}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package de.Ste3et_C0st.Furniture.Camera.Utils.v1_10;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.Ste3et_C0st.Furniture.Camera.Utils.MinecraftBlockColor;
|
||||
|
||||
public class BlockColor extends MinecraftBlockColor{
|
||||
|
||||
private static Class<?> iBlockDataClazz,BlockClazz, MaterialMapColorClazz;
|
||||
|
||||
static {
|
||||
try {
|
||||
BlockClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".Block");
|
||||
iBlockDataClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".IBlockData");
|
||||
MaterialMapColorClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".MaterialMapColor");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getBlockColor(Block b) {
|
||||
try {
|
||||
int combined = b.getType().getId() + (b.getData() << 12);
|
||||
|
||||
Method iBlockDataMethod = BlockClazz.getDeclaredMethod("getByCombinedId", int.class);
|
||||
Object iblockData = iBlockDataMethod.invoke(null, combined);
|
||||
|
||||
Method getBlockMethod = iBlockDataClazz.getMethod("getBlock");
|
||||
Object nmsBlock = getBlockMethod.invoke(iblockData);
|
||||
|
||||
Field BlockFieldy = BlockClazz.getDeclaredField("y");
|
||||
BlockFieldy.setAccessible(true);
|
||||
Object materialMapColor = BlockFieldy.get(nmsBlock);
|
||||
|
||||
Field MaterialMapColorFieldM = MaterialMapColorClazz.getDeclaredField("M");
|
||||
MaterialMapColorFieldM.setAccessible(true);
|
||||
int color = MaterialMapColorFieldM.getInt(materialMapColor) * 4;
|
||||
|
||||
return (byte) color;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package de.Ste3et_C0st.Furniture.Camera.Utils.v1_11;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.Ste3et_C0st.Furniture.Camera.Utils.MinecraftBlockColor;
|
||||
|
||||
public class BlockColor extends MinecraftBlockColor{
|
||||
|
||||
private static Class<?> iBlockDataClazz,BlockClazz, MaterialMapColorClazz;
|
||||
|
||||
static {
|
||||
try {
|
||||
BlockClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".Block");
|
||||
iBlockDataClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".IBlockData");
|
||||
MaterialMapColorClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".MaterialMapColor");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getBlockColor(Block b) {
|
||||
try {
|
||||
int combined = b.getType().getId() + (b.getData() << 12);
|
||||
|
||||
Method iBlockDataMethod = BlockClazz.getDeclaredMethod("getByCombinedId", int.class);
|
||||
Object iblockData = iBlockDataMethod.invoke(null, combined);
|
||||
|
||||
Method getBlockMethod = iBlockDataClazz.getMethod("getBlock");
|
||||
Object nmsBlock = getBlockMethod.invoke(iblockData);
|
||||
|
||||
Field BlockFieldy = BlockClazz.getDeclaredField("y");
|
||||
BlockFieldy.setAccessible(true);
|
||||
Object materialMapColor = BlockFieldy.get(nmsBlock);
|
||||
|
||||
Field MaterialMapColorFieldM = MaterialMapColorClazz.getDeclaredField("M");
|
||||
MaterialMapColorFieldM.setAccessible(true);
|
||||
int color = MaterialMapColorFieldM.getInt(materialMapColor) * 4;
|
||||
|
||||
return (byte) color;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package de.Ste3et_C0st.Furniture.Camera.Utils.v1_12;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.Ste3et_C0st.Furniture.Camera.Utils.MinecraftBlockColor;
|
||||
|
||||
public class BlockColor extends MinecraftBlockColor{
|
||||
|
||||
private static Class<?> iBlockDataClazz,BlockClazz, MaterialMapColorClazz;
|
||||
|
||||
static {
|
||||
try {
|
||||
BlockClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".Block");
|
||||
iBlockDataClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".IBlockData");
|
||||
MaterialMapColorClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".MaterialMapColor");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getBlockColor(Block b) {
|
||||
try {
|
||||
int combined = b.getType().getId() + (b.getData() << 12);
|
||||
|
||||
Method iBlockDataMethod = BlockClazz.getDeclaredMethod("getByCombinedId", int.class);
|
||||
Object iblockData = iBlockDataMethod.invoke(null, combined);
|
||||
|
||||
Method getBlockMethod = iBlockDataClazz.getMethod("getBlock");
|
||||
Object nmsBlock = getBlockMethod.invoke(iblockData);
|
||||
|
||||
Field BlockFieldy = BlockClazz.getDeclaredField("y");
|
||||
BlockFieldy.setAccessible(true);
|
||||
Object materialMapColor = BlockFieldy.get(nmsBlock);
|
||||
|
||||
Field MaterialMapColorFieldM = MaterialMapColorClazz.getDeclaredField("ad");
|
||||
MaterialMapColorFieldM.setAccessible(true);
|
||||
int color = MaterialMapColorFieldM.getInt(materialMapColor) * 4;
|
||||
|
||||
return (byte) color;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package de.Ste3et_C0st.Furniture.Camera.Utils.v1_13;
|
||||
|
||||
import org.apache.commons.lang.reflect.MethodUtils;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.Ste3et_C0st.Furniture.Camera.Utils.MinecraftBlockColor;
|
||||
|
||||
public class BlockColor extends MinecraftBlockColor{
|
||||
|
||||
private static Class<?> CraftMagicNumbersClass;
|
||||
|
||||
static {
|
||||
try {
|
||||
CraftMagicNumbersClass = Class.forName("org.bukkit.craftbukkit." + getBukkitVersion() + ".util.CraftMagicNumbers");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getBlockColor(Block b) {
|
||||
try {
|
||||
Object nmsBlock = CraftMagicNumbersClass.getMethod("getBlock", org.bukkit.Material.class).invoke(null, b.getType());
|
||||
Object iBlockData = nmsBlock.getClass().getMethod("getBlockData").invoke(nmsBlock);
|
||||
Object Material = MethodUtils.invokeMethod(iBlockData, "getMaterial", null);
|
||||
Object MaterialMapColor = MethodUtils.invokeMethod(Material, "i", null);
|
||||
int color = MaterialMapColor.getClass().getField("ac").getInt(MaterialMapColor) * 4;
|
||||
return (byte) color;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package de.Ste3et_C0st.Furniture.Camera.Utils.v1_14;
|
||||
|
||||
import org.apache.commons.lang.reflect.MethodUtils;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.Ste3et_C0st.Furniture.Camera.Utils.MinecraftBlockColor;
|
||||
|
||||
public class BlockColor extends MinecraftBlockColor{
|
||||
|
||||
private static Class<?> CraftMagicNumbersClass;
|
||||
|
||||
static {
|
||||
try {
|
||||
CraftMagicNumbersClass = Class.forName("org.bukkit.craftbukkit." + getBukkitVersion() + ".util.CraftMagicNumbers");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getBlockColor(Block b) {
|
||||
try {
|
||||
Object nmsBlock = CraftMagicNumbersClass.getMethod("getBlock", org.bukkit.Material.class).invoke(null, b.getType());
|
||||
Object iBlockData = nmsBlock.getClass().getMethod("getBlockData").invoke(nmsBlock);
|
||||
Object Material = MethodUtils.invokeMethod(iBlockData, "getMaterial", null);
|
||||
Object MaterialMapColor = MethodUtils.invokeMethod(Material, "i", null);
|
||||
int color = MaterialMapColor.getClass().getField("ac").getInt(MaterialMapColor) * 4;
|
||||
return (byte) color;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package de.Ste3et_C0st.Furniture.Camera.Utils.v1_15;
|
||||
|
||||
import org.apache.commons.lang.reflect.MethodUtils;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.Ste3et_C0st.Furniture.Camera.Utils.MinecraftBlockColor;
|
||||
|
||||
public class BlockColor extends MinecraftBlockColor{
|
||||
|
||||
private static Class<?> CraftMagicNumbersClass;
|
||||
|
||||
static {
|
||||
try {
|
||||
CraftMagicNumbersClass = Class.forName("org.bukkit.craftbukkit." + getBukkitVersion() + ".util.CraftMagicNumbers");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getBlockColor(Block b) {
|
||||
try {
|
||||
Object nmsBlock = CraftMagicNumbersClass.getMethod("getBlock", org.bukkit.Material.class).invoke(null, b.getType());
|
||||
Object iBlockData = nmsBlock.getClass().getMethod("getBlockData").invoke(nmsBlock);
|
||||
Object Material = MethodUtils.invokeMethod(iBlockData, "getMaterial", null);
|
||||
Object MaterialMapColor = MethodUtils.invokeMethod(Material, "i", null);
|
||||
int color = MaterialMapColor.getClass().getField("ac").getInt(MaterialMapColor) * 4;
|
||||
return (byte) color;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package de.Ste3et_C0st.Furniture.Camera.Utils.v1_9;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.Ste3et_C0st.Furniture.Camera.Utils.MinecraftBlockColor;
|
||||
|
||||
public class BlockColor extends MinecraftBlockColor{
|
||||
|
||||
private static Class<?> iBlockDataClazz,BlockClazz, MaterialMapColorClazz;
|
||||
|
||||
static {
|
||||
try {
|
||||
BlockClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".Block");
|
||||
iBlockDataClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".IBlockData");
|
||||
MaterialMapColorClazz = Class.forName("net.minecraft.server." + getBukkitVersion() + ".MaterialMapColor");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getBlockColor(Block b) {
|
||||
try {
|
||||
int combined = b.getType().getId() + (b.getData() << 12);
|
||||
|
||||
Method iBlockDataMethod = BlockClazz.getDeclaredMethod("getByCombinedId", int.class);
|
||||
Object iblockData = iBlockDataMethod.invoke(null, combined);
|
||||
|
||||
Method getBlockMethod = iBlockDataClazz.getMethod("getBlock");
|
||||
Object nmsBlock = getBlockMethod.invoke(iblockData);
|
||||
|
||||
Field BlockFieldy = BlockClazz.getDeclaredField("y");
|
||||
BlockFieldy.setAccessible(true);
|
||||
Object materialMapColor = BlockFieldy.get(nmsBlock);
|
||||
|
||||
Field MaterialMapColorFieldM = MaterialMapColorClazz.getDeclaredField("M");
|
||||
MaterialMapColorFieldM.setAccessible(true);
|
||||
int color = MaterialMapColorFieldM.getInt(materialMapColor) * 4;
|
||||
|
||||
return (byte) color;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -26,25 +26,22 @@ public class camera extends Furniture{
|
|||
super(id);
|
||||
boolean b = false;
|
||||
for(fEntity stand : id.getPacketList()){
|
||||
if(stand.isCustomNameVisible()) {
|
||||
b = true;
|
||||
stand.setNameVasibility(false);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(b){
|
||||
update();
|
||||
}
|
||||
if(b) update();
|
||||
}
|
||||
|
||||
public void setZoom(){
|
||||
|
@ -79,7 +76,6 @@ public class camera extends Furniture{
|
|||
if(getObjID() == null) return;
|
||||
if(getObjID().getSQLAction().equals(SQLAction.REMOVE)) return;
|
||||
if(player == null) return;
|
||||
player.sendMessage("test");
|
||||
Location pLocation = getLutil().getRelativ(player.getLocation().getBlock().getLocation(), getBlockFace(), -1D, 0D).clone();
|
||||
Location locCopy = getLocation().getBlock().getLocation().clone();
|
||||
pLocation.setYaw(locCopy.getYaw());
|
||||
|
|
Loading…
Reference in New Issue