Model system mostly implemented. Encountered an Armor Stand bug, but

otherwise system is ready to go.
This commit is contained in:
sigonasr2 2017-10-12 21:10:16 -05:00
parent 7cc2b9a7e2
commit 49325dedc1
14 changed files with 622 additions and 20 deletions

Binary file not shown.

View File

@ -2495,6 +2495,15 @@ public class CustomDamage {
return true; //Cancel any damage events in Spectator mode or Creative Mode. return true; //Cancel any damage events in Spectator mode or Creative Mode.
} }
if (target.isInvulnerable()) { if (target.isInvulnerable()) {
if (shooter instanceof Player && shooter.hasPermission("TwosideKeeper.modifyModels")) {
Player p = (Player)shooter;
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
if (EntityUtils.isValidEntity(target) &&
target instanceof ArmorStand) {
shooter.sendMessage("Selected Armor Stand "+ChatColor.GREEN+target.getUniqueId());
pd.myStand = (ArmorStand)target;
}
}
return true; //Cancel any damage events when the target is invulnerable. return true; //Cancel any damage events when the target is invulnerable.
} }
if (isFlagSet(flags,IGNORE_DAMAGE_TICK)) { if (isFlagSet(flags,IGNORE_DAMAGE_TICK)) {
@ -4209,7 +4218,7 @@ public class CustomDamage {
*/ */
private static double getDamageLimit(LivingEntity target) { private static double getDamageLimit(LivingEntity target) {
double pct = 1.0; double pct = 1.0;
if (GenericFunctions.isBossMonster(target)) { if (target!=null && !(target instanceof Player) && GenericFunctions.isBossMonster(target)) {
pct = BOSS_DAMAGE_LIMIT; pct = BOSS_DAMAGE_LIMIT;
} }
return pct; return pct;

View File

@ -0,0 +1,33 @@
package sig.plugin.TwosideKeeper.HelperStructures;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import sig.plugin.TwosideKeeper.HelperStructures.Common.ArmorStandProperties;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.EntityUtils;
public class ArmorStandLinker {
ArmorStandProperties myModel;
ArmorStand ent;
Location loc;
public ArmorStandLinker(Location loc) {
ent = (ArmorStand)loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
this.loc=loc;
}
public void run() {
if (!EntityUtils.isValidEntity(ent)) {
ent = (ArmorStand)loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
}
}
public void setLocation(Location loc) {
this.loc=loc.clone();
}
public Location getLocation() {
return loc;
}
}

View File

@ -1,15 +1,20 @@
package sig.plugin.TwosideKeeper.HelperStructures.Common; package sig.plugin.TwosideKeeper.HelperStructures.Common;
import java.lang.reflect.Field;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle; import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.JavaUtils;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.MathUtils; import sig.plugin.TwosideKeeper.HelperStructures.Utils.MathUtils;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.ReflectUtils;
public class ArmorStandProperties { public class ArmorStandProperties {
final public static ArmorStandProperties SCEPTERBASE = new ArmorStandProperties(); final public static ArmorStandProperties SCEPTERBASE = new ArmorStandProperties();
final public static ArmorStandProperties SCEPTERTOP = new ArmorStandProperties(); final public static ArmorStandProperties SCEPTERTOP = new ArmorStandProperties();
final public static ArmorStandProperties BLANK = new ArmorStandProperties();
boolean arms = false; boolean arms = false;
boolean baseplate = false; boolean baseplate = false;
@ -30,12 +35,46 @@ public class ArmorStandProperties {
boolean visible=true; boolean visible=true;
boolean customNameVisible=false; boolean customNameVisible=false;
String customName=""; String customName="";
boolean gravity=false;
Vector offset = new Vector(); Vector offset = new Vector();
Vector dir = new Vector();
public ArmorStandProperties() { public ArmorStandProperties() {
} }
public ArmorStandProperties clone() {
ArmorStandProperties newpos = new ArmorStandProperties();
for (Field f : this.getClass().getDeclaredFields()) {
if (ReflectUtils.isCloneable(f)) {
try {
f.set(newpos, f.get(this));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return newpos;
}
public Vector getFacingDirection() {
return dir;
}
public void setFacingDirection(Vector dir) {
this.dir=dir;
}
public void setGravity(boolean gravity) {
this.gravity=gravity;
}
public boolean isGravityOn() {
return this.gravity;
}
public boolean isArms() { public boolean isArms() {
return arms; return arms;
} }

View File

@ -99,6 +99,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.CubeType;
import sig.plugin.TwosideKeeper.HelperStructures.CustomItem; import sig.plugin.TwosideKeeper.HelperStructures.CustomItem;
import sig.plugin.TwosideKeeper.HelperStructures.EliteMonsterLocationFinder; import sig.plugin.TwosideKeeper.HelperStructures.EliteMonsterLocationFinder;
import sig.plugin.TwosideKeeper.HelperStructures.ItemSet; import sig.plugin.TwosideKeeper.HelperStructures.ItemSet;
import sig.plugin.TwosideKeeper.HelperStructures.LivingEntityDifficulty;
import sig.plugin.TwosideKeeper.HelperStructures.PlayerMode; import sig.plugin.TwosideKeeper.HelperStructures.PlayerMode;
import sig.plugin.TwosideKeeper.HelperStructures.WorldShop; import sig.plugin.TwosideKeeper.HelperStructures.WorldShop;
import sig.plugin.TwosideKeeper.HelperStructures.Effects.WindSlash; import sig.plugin.TwosideKeeper.HelperStructures.Effects.WindSlash;
@ -2311,12 +2312,16 @@ public class GenericFunctions {
} }
public static boolean isBossMonster(LivingEntity m) { public static boolean isBossMonster(LivingEntity m) {
LivingEntityDifficulty dif = null;
if (m!=null) {
dif = MonsterController.getLivingEntityDifficulty(m);
}
if (MonsterController.isZombieLeader(m) || if (MonsterController.isZombieLeader(m) ||
(m.getType()==EntityType.GUARDIAN && (m.getType()==EntityType.GUARDIAN &&
((Guardian)m).isElder()) || ((Guardian)m).isElder()) ||
m.getType()==EntityType.ENDER_DRAGON || m.getType()==EntityType.ENDER_DRAGON ||
m.getType()==EntityType.WITHER || m.getType()==EntityType.WITHER ||
MonsterController.getLivingEntityDifficulty(m).name().contains("MINIBOSS") || (dif!=null && dif.name().contains("MINIBOSS")) ||
LivingEntityStructure.GetLivingEntityStructure(m).getLeader() || LivingEntityStructure.GetLivingEntityStructure(m).getLeader() ||
LivingEntityStructure.GetLivingEntityStructure(m).getElite()) { LivingEntityStructure.GetLivingEntityStructure(m).getElite()) {
return true; return true;

View File

@ -1,28 +1,62 @@
package sig.plugin.TwosideKeeper.HelperStructures; package sig.plugin.TwosideKeeper.HelperStructures;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.HelperStructures.Common.ArmorStandProperties; import sig.plugin.TwosideKeeper.HelperStructures.Common.ArmorStandProperties;
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.EntityUtils;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.FileUtils;
public class CustomModel { public class CustomModel {
List<ArmorStandProperties> modelParts = new ArrayList<ArmorStandProperties>(); public List<ArmorStandProperties> modelParts = new ArrayList<ArmorStandProperties>();
List<ArmorStand> stands = new ArrayList<ArmorStand>(); public List<ArmorStand> stands = new ArrayList<ArmorStand>();
Location origin;
public CustomModel(Location loc, ArmorStandProperties...modelParts) { public CustomModel(Location loc, ArmorStandProperties...modelParts) {
origin = loc.clone();
for (ArmorStandProperties asp : modelParts) { for (ArmorStandProperties asp : modelParts) {
this.modelParts.add(asp); AddModelPart(asp);
this.stands.add(setupArmorStand(loc, asp));
} }
} }
private ArmorStand setupArmorStand(Location loc, ArmorStandProperties asp) { public static ArmorStandProperties getPropertyFromStand(UUID id) {
ArmorStand stand = (ArmorStand)loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND); for (CustomModel model : TwosideKeeper.models) {
for (int i=0;i<model.stands.size();i++) {
ArmorStand stand = model.stands.get(i);
if (EntityUtils.isValidEntity(stand) &&
stand.getUniqueId().equals(id)) {
return model.modelParts.get(i);
}
}
}
return null;
}
public static ArmorStandProperties getPropertyFromStand(ArmorStand stand) {
return getPropertyFromStand(stand.getUniqueId());
}
private ArmorStand setupArmorStand(ArmorStandProperties asp) {
return setupArmorStand(origin,asp);
}
private ArmorStand setupArmorStand(Location defaultSpawn, ArmorStandProperties asp) {
ArmorStand stand = (ArmorStand)origin.getWorld().spawnEntity(defaultSpawn.clone(), EntityType.ARMOR_STAND);
stand.setArms(asp.isArms()); stand.setArms(asp.isArms());
stand.setBasePlate(asp.isBaseplate()); stand.setBasePlate(asp.isBaseplate());
stand.setBodyPose(asp.getBodyPose()); stand.setBodyPose(asp.getBodyPose());
@ -41,15 +75,183 @@ public class CustomModel {
stand.setVisible(asp.isVisible()); stand.setVisible(asp.isVisible());
stand.setCustomNameVisible(asp.isCustomNameVisible()); stand.setCustomNameVisible(asp.isCustomNameVisible());
stand.setCustomName(asp.getCustomName()); stand.setCustomName(asp.getCustomName());
stand.teleport(loc.add(asp.getOffset())); stand.teleport(origin.add(asp.getOffset()));
stand.setRemoveWhenFarAway(true);
stand.setGravity(false);
stand.setInvulnerable(true);
return stand; return stand;
} }
public void displayModel(Location loc) { public void AddModelPart(ArmorStandProperties aspOld) {
AddModelPart(origin,aspOld);
}
public void AddModelPart(Location defaultSpawn, ArmorStandProperties aspOld) {
//ArmorStandProperties asp = aspOld.clone();
//asp.setOffset(new Vector(loc.getX()-origin.getX(),loc.getY()-origin.getY(),loc.getZ()-origin.getZ()));
this.modelParts.add(aspOld);
this.stands.add(setupArmorStand(defaultSpawn,aspOld));
TwosideKeeper.log("Added model! New part count: "+stands.size(), 1);
}
public void displayModel() {
for (int i=0;i<stands.size();i++) { for (int i=0;i<stands.size();i++) {
if (stands.get(i)!=null && stands.get(i).isValid()) { if (stands.get(i)!=null && stands.get(i).isValid()) {
stands.get(i).teleport(loc.add(modelParts.get(i).getOffset())); Location newpos = origin.clone().add(modelParts.get(i).getOffset());
stands.get(i).teleport(newpos);
} else {
Location oldPos = stands.get(i).getLocation().clone();
stands.get(i).remove();
stands.set(i, setupArmorStand(oldPos,modelParts.get(i)));
TwosideKeeper.log("Recreated Part "+i, 1);
} }
} }
} }
public void loadModel(Location loc, String modelName) {
String[] properties = FileUtils.readFromFile(TwosideKeeper.plugin.getDataFolder()+"/models/"+modelName);
int modelCount = properties[0].split(",").length-1;
cleanup();
for (int i=0;i<modelCount;i++) {
String[] modelprops = new String[properties.length];
for (int j=0;j<properties.length;j++) {
modelprops[j] = properties[j].split(",")[i+1];
}
int k=0;
ArmorStandProperties modelProp = new ArmorStandProperties();
modelProp.setArms(Boolean.parseBoolean(modelprops[k++]));
modelProp.setBaseplate(Boolean.parseBoolean(modelprops[k++]));
modelProp.setBodyPose(parseEulerAngle(modelprops[k++]));
modelProp.setBoots(parseItemStack(modelprops[k++]));
modelProp.setChestplate(parseItemStack(modelprops[k++]));
modelProp.setHeadPose(parseEulerAngle(modelprops[k++]));
modelProp.setHelmet(parseItemStack(modelprops[k++]));
modelProp.setHand(parseItemStack(modelprops[k++]));
modelProp.setLeftArmPose(parseEulerAngle(modelprops[k++]));
modelProp.setLeftLegPose(parseEulerAngle(modelprops[k++]));
modelProp.setLeggings(parseItemStack(modelprops[k++]));
modelProp.setMarker(Boolean.parseBoolean(modelprops[k++]));
modelProp.setRightArmPose(parseEulerAngle(modelprops[k++]));
modelProp.setRightLegPose(parseEulerAngle(modelprops[k++]));
modelProp.setSmall(Boolean.parseBoolean(modelprops[k++]));
modelProp.setVisible(Boolean.parseBoolean(modelprops[k++]));
modelProp.setCustomNameVisible(Boolean.parseBoolean(modelprops[k++]));
modelProp.setCustomName(modelprops[k++]);
modelProp.setOffset(parseVector(modelprops[k++]));
modelProp.setFacingDirection(parseVector(modelprops[k++]));
modelProp.setGravity(Boolean.parseBoolean(modelprops[k++]));
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, ()->{
AddModelPart(origin.clone().add(modelProp.getOffset()),modelProp);
},(i+1)*20);
/*modelParts.add(modelProp);
stands.add(setupArmorStand(loc,modelProp));*/
}
}
public ItemStack parseItemStack(String csvString) {
String[] parse = csvString.split(";");
ItemStack item = new ItemStack(Material.valueOf(parse[0]));
boolean isEnchanted = Boolean.parseBoolean(parse[1]);
if (isEnchanted) {
item.addUnsafeEnchantment(Enchantment.values()[(int)(Math.random()*Enchantment.values().length)], 9);
}
return item;
}
public Vector parseVector(String csvString) {
String[] parse = csvString.split(";");
return new Vector(Double.parseDouble(parse[0]),Double.parseDouble(parse[1]),Double.parseDouble(parse[2]));
}
public EulerAngle parseEulerAngle(String csvString) {
String[] parse = csvString.split(";");
return new EulerAngle(Double.parseDouble(parse[0]),Double.parseDouble(parse[1]),Double.parseDouble(parse[2]));
}
public void saveModel(String modelName) {
StringBuilder[] propertyName = new StringBuilder[]{new StringBuilder("Arms,"),
new StringBuilder("BasePlate,"),
new StringBuilder("BodyPose,"),
new StringBuilder("Boots,"),
new StringBuilder("Chestplate,"),
new StringBuilder("HeadPose,"),
new StringBuilder("Helmet,"),
new StringBuilder("ItemInHand,"),
new StringBuilder("LeftArmPose,"),
new StringBuilder("LeftLegPose,"),
new StringBuilder("Leggings,"),
new StringBuilder("Marker,"),
new StringBuilder("RighArmPose,"),
new StringBuilder("RightLegPose,"),
new StringBuilder("Small,"),
new StringBuilder("Visible,"),
new StringBuilder("CustomNameVisible,"),
new StringBuilder("CustomName,"),
new StringBuilder("Offset,"),
new StringBuilder("Direction,"),
new StringBuilder("Gravity,")};
for (int j=0;j<stands.size();j++) {
ArmorStand stand = stands.get(j);
ArmorStandProperties asp = modelParts.get(j);
int i=0;
propertyName[i++].append(stand.hasArms()+",");
propertyName[i++].append(stand.hasBasePlate()+",");
propertyName[i++].append(ConvertEulerAngle(stand.getBodyPose())+",");
propertyName[i++].append(ConvertItemStack(stand.getBoots())+",");
propertyName[i++].append(ConvertItemStack(stand.getChestplate())+",");
propertyName[i++].append(ConvertEulerAngle(stand.getHeadPose())+",");
propertyName[i++].append(ConvertItemStack(stand.getHelmet())+",");
propertyName[i++].append(ConvertItemStack(stand.getItemInHand())+",");
propertyName[i++].append(ConvertEulerAngle(stand.getLeftArmPose())+",");
propertyName[i++].append(ConvertEulerAngle(stand.getLeftLegPose())+",");
propertyName[i++].append(ConvertItemStack(stand.getLeggings())+",");
propertyName[i++].append(stand.isMarker()+",");
propertyName[i++].append(ConvertEulerAngle(stand.getRightArmPose())+",");
propertyName[i++].append(ConvertEulerAngle(stand.getRightLegPose())+",");
propertyName[i++].append(stand.isSmall()+",");
propertyName[i++].append(stand.isVisible()+",");
propertyName[i++].append(stand.isCustomNameVisible()+",");
propertyName[i++].append(stand.getCustomName()+",");
propertyName[i++].append(ConvertVector(asp.getOffset())+",");
propertyName[i++].append(ConvertVector(asp.getFacingDirection())+",");
propertyName[i++].append(stand.hasGravity()+",");
}
String[] finalString = new String[propertyName.length];
int j=0;
for (int i=0;i<propertyName.length;i++) {
StringBuilder builder = propertyName[i];
finalString[j++] = builder.toString();
}
FileUtils.writetoFile(finalString, TwosideKeeper.plugin.getDataFolder()+"/models/"+modelName);
}
private String ConvertItemStack(ItemStack item) {
return item.getType()+";"+((item.getEnchantments().size()>0)?Boolean.toString(true):Boolean.toString(false));
}
private String ConvertEulerAngle(EulerAngle angle) {
return angle.getX()+";"+angle.getY()+";"+angle.getZ();
}
private String ConvertVector(Vector angle) {
return angle.getX()+";"+angle.getY()+";"+angle.getZ();
}
public static void cleanup(CustomModel model) {
model.cleanup();
TwosideKeeper.models.remove(model);
model=null;
}
public void cleanup() {
for (ArmorStand stand : stands) {
TwosideKeeper.log("Removing entity ("+GenericFunctions.getDisplayName(stand)+")"+stand.getUniqueId(), 1);
stand.remove();
}
stands.clear();
modelParts.clear();
}
} }

View File

@ -16,11 +16,13 @@ public class DamageLabel{
ArmorStand aec; ArmorStand aec;
double spd; double spd;
int duration; int duration;
Location loc;
public DamageLabel(ArmorStand aec, double spd, int duration) { public DamageLabel(Location loc, ArmorStand aec, double spd, int duration) {
this.aec=aec; this.aec=aec;
this.spd=spd; this.spd=spd;
this.duration=duration; this.duration=duration;
this.loc=loc;
} }
public boolean run() { public boolean run() {
@ -29,7 +31,11 @@ public class DamageLabel{
/*if (duration>0) { /*if (duration>0) {
Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, new CloudRunnableRemoveLabel(aec.getLocation().add(0,spd,0).clone(),aec.getCustomName(),spd,duration), 1); Bukkit.getScheduler().runTaskLater(TwosideKeeper.plugin, new CloudRunnableRemoveLabel(aec.getLocation().add(0,spd,0).clone(),aec.getCustomName(),spd,duration), 1);
}*/ }*/
if (loc!=null) {
aec.teleport(loc.add(0,spd,0));
} else {
aec.teleport(aec.getLocation().add(0,spd,0)); aec.teleport(aec.getLocation().add(0,spd,0));
}
if (duration<0) { if (duration<0) {
aec.remove(); aec.remove();
return false; return false;

View File

@ -0,0 +1,42 @@
package sig.plugin.TwosideKeeper.HelperStructures;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Location;
import sig.plugin.TwosideKeeper.HelperStructures.Common.ArmorStandProperties;
import utils.Utils.Vector3D;
public class Model {
List<ArmorStandProperties> modelParts = new ArrayList<ArmorStandProperties>();
List<ArmorStandLinker> models = new ArrayList<ArmorStandLinker>();
Location loc;
Vector3D offset = new Vector3D(0,0,0);
double degreeRotation = 0;
public Model(Location loc, ArmorStandProperties...modelParts) {
this.modelParts = Arrays.asList(modelParts);
for (ArmorStandProperties prop : modelParts) {
models.add(new ArmorStandLinker(loc));
}
this.loc=loc;
}
public void run() {
for (ArmorStandLinker parts : models) {
parts.run();
parts.setLocation(loc);
}
}
public void setLocation(Location loc) {
this.loc = loc.clone();
}
public Location getLocation() {
return loc;
}
}

View File

@ -79,8 +79,8 @@ public class EntityUtils {
public static void applyDamageIndicator(Entity e, double damage, IndicatorType type) { public static void applyDamageIndicator(Entity e, double damage, IndicatorType type) {
Location offsetloc = e.getLocation().add(Math.random()/2-0.25,0.5,Math.random()/2-0.25); Location offsetloc = e.getLocation().add(Math.random()/2-0.25,0.5,Math.random()/2-0.25);
if (damage>=1) { if (damage>=1) {
ArmorStand aec = CreateOverlayText(offsetloc,((damage>=100)?ChatColor.BOLD+" ":"")+type.getColor()+Integer.toString((int)damage)+((damage>=100)?" ":"")); ArmorStand aec = CreateOverlayText(new Location(offsetloc.getWorld(),offsetloc.getX(),32648,offsetloc.getZ()),((damage>=100)?ChatColor.BOLD+" ":"")+type.getColor()+Integer.toString((int)damage)+((damage>=100)?" ":""));
TwosideKeeper.labelqueue.add(new DamageLabel(aec,0.1,(int)(10*Math.min(Math.max(1,(double)damage/50),2)))); TwosideKeeper.labelqueue.add(new DamageLabel(offsetloc,aec,0.1,(int)(10*Math.min(Math.max(1,(double)damage/50),2))));
} }
} }

View File

@ -1,12 +1,24 @@
package sig.plugin.TwosideKeeper.HelperStructures.Utils; package sig.plugin.TwosideKeeper.HelperStructures.Utils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.net.URL;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
public class FileUtils { public class FileUtils {
public static String[] readFromFile(String filename) { public static String[] readFromFile(String filename) {
File file = new File(filename); File file = new File(filename);
@ -32,4 +44,114 @@ public class FileUtils {
} }
return contents.toArray(new String[contents.size()]); return contents.toArray(new String[contents.size()]);
} }
private static String readAll(Reader rd) throws IOException {
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1) {
sb.append((char) cp);
}
return sb.toString();
}
public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
InputStream is = new URL(url).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
JSONObject json = new JSONObject(jsonText);
jsonText=null;
return json;
} finally {
is.close();
}
}
public static JSONObject readJsonFromFile(String file) throws IOException, JSONException {
InputStream is = new FileInputStream(new File(file));
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
JSONObject json = new JSONObject(jsonText);
jsonText=null;
return json;
} finally {
is.close();
}
}
public static JSONObject readJsonFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException {
InputStream is = new URL(url).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
if (writeToFile) {
writetoFile(new String[]{jsonText},file);
}
JSONObject json = new JSONObject(jsonText);
return json;
} finally {
is.close();
}
}
public static void logToFile(String message, String filename) {
File file = new File(filename);
try {
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(message);
pw.flush();
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void writetoFile(String[] data, String filename) {
File file = new File(filename);
try {
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file,false);
PrintWriter pw = new PrintWriter(fw);
for (String s : data) {
pw.println(s);
}
pw.flush();
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void copyFile(File source, File dest) throws IOException {
FileChannel sourceChannel = null;
FileChannel destChannel = null;
try {
sourceChannel = new FileInputStream(source).getChannel();
destChannel = new FileOutputStream(dest).getChannel();
destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
}finally{
sourceChannel.close();
destChannel.close();
}
}
public static void deleteFile(String filename) {
File file = new File(filename);
if (file.exists()) {
file.delete();
}
}
} }

View File

@ -0,0 +1,49 @@
package sig.plugin.TwosideKeeper.HelperStructures.Utils;
import java.lang.reflect.Field;
public class JavaUtils {
public JavaUtils clone() {
JavaUtils newpos = new JavaUtils();
for (Field f : this.getClass().getDeclaredFields()) {
if (ReflectUtils.isCloneable(f)) {
try {
f.set(newpos, f.get(this));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return newpos;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.getClass().getName()+"(");
boolean first=false;
for (Field f : this.getClass().getDeclaredFields()) {
if (!ReflectUtils.isCloneable(f)) {
if (!first) {
try {
sb.append(f.getName()+"="+f.get(this));
first=true;
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} else {
try {
sb.append(","+f.getName()+"="+f.get(this));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
sb.append(")");
return sb.toString();
}
}

View File

@ -0,0 +1,9 @@
package sig.plugin.TwosideKeeper.HelperStructures.Utils;
import java.lang.reflect.Field;
public class ReflectUtils {
public static boolean isCloneable(Field f) {
int mods = f.getModifiers();
return mods<8;
}
}

View File

@ -1180,6 +1180,15 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
} }
public void SetupFolders(String...folders) {
for (String s : folders) {
File fold = new File(TwosideKeeper.plugin.getDataFolder()+"/"+s);
if (!fold.exists()) {
fold.mkdirs();
}
}
}
@Override @Override
public void onEnable() { public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
@ -1188,6 +1197,18 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
loadConfig(); loadConfig();
SetupFolders("arrowquivers",
"books",
"debug",
"inventorybackup",
"itemcubes",
"itemrecords",
"logs",
"models",
"records",
"updates",
"users");
CustomItem.InitializeItemRecipes(); CustomItem.InitializeItemRecipes();
Recipes.Initialize_ItemCube_Recipes(); Recipes.Initialize_ItemCube_Recipes();
Recipes.Initialize_ArrowQuiver_Recipe(); Recipes.Initialize_ArrowQuiver_Recipe();
@ -1526,6 +1547,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
ReplaceBlockTask.CleanupTemporaryBlock(tb); ReplaceBlockTask.CleanupTemporaryBlock(tb);
} }
log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG); log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG);
betweentime = System.currentTimeMillis();
log("Resetting Mob Names ["+livingentitydata.size()+"]",CLEANUP_DEBUG); log("Resetting Mob Names ["+livingentitydata.size()+"]",CLEANUP_DEBUG);
for (UUID id : livingentitydata.keySet()) { for (UUID id : livingentitydata.keySet()) {
//TemporaryBlock tb = temporaryblocks.get(ss); //TemporaryBlock tb = temporaryblocks.get(ss);
@ -1535,16 +1557,24 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
//TwosideKeeper.log("Saving unloaded monster "+les.getUnloadedName(), 0); //TwosideKeeper.log("Saving unloaded monster "+les.getUnloadedName(), 0);
} }
log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG); log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG);
betweentime = System.currentTimeMillis();
log("Removing Instances ["+roominstances.size()+"]",CLEANUP_DEBUG); log("Removing Instances ["+roominstances.size()+"]",CLEANUP_DEBUG);
for (Room room : roominstances) { for (Room room : roominstances) {
room.killWorld(); room.killWorld();
} }
log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG); log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG);
betweentime = System.currentTimeMillis();
log("Removing Damage Labels ["+labelqueue.size()+"]",CLEANUP_DEBUG); log("Removing Damage Labels ["+labelqueue.size()+"]",CLEANUP_DEBUG);
for (DamageLabel label : labelqueue) { for (DamageLabel label : labelqueue) {
label.cleanup(); label.cleanup();
} }
log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG); log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG);
betweentime = System.currentTimeMillis();
log("Removing Models ["+models.size()+"]",CLEANUP_DEBUG);
for (CustomModel model : models) {
model.cleanup();
}
log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG);
long endtime = System.currentTimeMillis(); long endtime = System.currentTimeMillis();
log("Cleanup Maintenance completed. Total Time: "+(endtime-starttime)+"ms.",CLEANUP_DEBUG); log("Cleanup Maintenance completed. Total Time: "+(endtime-starttime)+"ms.",CLEANUP_DEBUG);
} }
@ -2871,7 +2901,14 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
case 19:{ case 19:{
Location currentloc = pd.myStand.getLocation().clone(); Location currentloc = pd.myStand.getLocation().clone();
currentloc.add(Double.parseDouble(args[2]),Double.parseDouble(args[3]),Double.parseDouble(args[4])); currentloc.add(Double.parseDouble(args[2]),Double.parseDouble(args[3]),Double.parseDouble(args[4]));
pd.myStand.teleport(currentloc); ArmorStandProperties prop = CustomModel.getPropertyFromStand(pd.myStand.getUniqueId());
Vector currentOffset = prop.getOffset();
prop.setOffset(new Vector(currentOffset.getX()+Double.parseDouble(args[2]),currentOffset.getY()+Double.parseDouble(args[3]),currentOffset.getZ()+Double.parseDouble(args[4])));
}break;
case 20:{
ArmorStandProperties prop = CustomModel.getPropertyFromStand(pd.myStand.getUniqueId());
Vector facingDirection = p.getLocation().getDirection();
prop.setFacingDirection(facingDirection);
}break; }break;
} }
}break; }break;
@ -2925,6 +2962,36 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
aPlugin.API.setItem(p, p.getOpenInventory(), i, new ItemStack(Material.ACACIA_DOOR_ITEM)); aPlugin.API.setItem(p, p.getOpenInventory(), i, new ItemStack(Material.ACACIA_DOOR_ITEM));
} }
}break; }break;
case "MODELS":{
if (args.length==1) {
CustomModel mymod = new CustomModel(p.getLocation(),new ArmorStandProperties[]{
ArmorStandProperties.BLANK
});
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
pd.myModel = mymod;
models.add(pd.myModel);
} else
{
switch (args[1]) {
case "add":{
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
pd.myModel.AddModelPart(ArmorStandProperties.BLANK);
}break;
case "save":{
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
pd.myModel.saveModel(args[2]);
}break;
case "load":{
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
pd.myModel.loadModel(p.getLocation(),args[2]);
}break;
case "remove":{
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
CustomModel.cleanup(pd.myModel);
}break;
}
}
}break;
} }
} }
//LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), MonsterDifficulty.ELITE); //LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), MonsterDifficulty.ELITE);
@ -7908,8 +7975,23 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
} }
if (e instanceof ArmorStand) { if (e instanceof ArmorStand) {
ArmorStand as = (ArmorStand)e; ArmorStand as = (ArmorStand)e;
if (as.getRemoveWhenFarAway()) { if (as.isInvulnerable()) {
removalEntities.add(e); removalEntities.add(e);
CustomModel killModel = null;
for (CustomModel model : models) {
for (ArmorStand stands : model.stands) {
if (stands.getUniqueId().equals(e.getUniqueId())) {
killModel = model;
break;
}
}
if (killModel!=null) {
break;
}
}
if (killModel!=null) {
CustomModel.cleanup(killModel);
}
} }
} }
} }

View File

@ -33,10 +33,14 @@ public class runServerTick implements Runnable{
TwosideKeeper.labelqueue.remove(i--); TwosideKeeper.labelqueue.remove(i--);
} }
} }
for (CustomModel model : TwosideKeeper.models) {
model.displayModel();
}
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
if (!aPluginAPIWrapper.isAFK(p)) { if (!aPluginAPIWrapper.isAFK(p)) {
//pd.myModel.displayModel(p.getLocation()); //pd.myModel.displayModel(p.getLocation());
//pd.myModel.displayModel();
if (pd.myPet!=null) { if (pd.myPet!=null) {
pd.myPet.run(); pd.myPet.run();
} }