diff --git a/.classpath b/.classpath index 0d7db5a..e94ecb9 100644 --- a/.classpath +++ b/.classpath @@ -2,9 +2,9 @@ - + diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index bdb13d5..cb2c649 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/sig/plugin/TwosideKeeper/DiscordStatusUpdater.java b/src/sig/plugin/TwosideKeeper/DiscordStatusUpdater.java index 64feca3..63c3017 100644 --- a/src/sig/plugin/TwosideKeeper/DiscordStatusUpdater.java +++ b/src/sig/plugin/TwosideKeeper/DiscordStatusUpdater.java @@ -12,7 +12,8 @@ public class DiscordStatusUpdater implements Runnable{ @Override public void run() { - DiscordMessageSender.setPlaying(ProduceMessage()); + //DiscordMessageSender.setPlaying(ProduceMessage()); + aPlugin.API.discordSetPlaying(ProduceMessage()); Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), this, 300l); } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index ec89006..1286411 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -4313,6 +4313,28 @@ public class GenericFunctions { e.printStackTrace(); } } + + public static void logToFile(String message, String filename) { + try { + if (!TwosideKeeper.filesave.exists()) { + TwosideKeeper.filesave.mkdir(); + } + + File saveTo = new File(TwosideKeeper.filesave, filename); + if (!saveTo.exists()) { + saveTo.createNewFile(); + } + + FileWriter fw = new FileWriter(saveTo, true); + PrintWriter pw = new PrintWriter(fw); + + pw.println(message); + pw.flush(); + pw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } public static boolean isSkullItem(ItemStack item) { if (item!=null && diff --git a/src/sig/plugin/TwosideKeeper/LivingEntityStructure.java b/src/sig/plugin/TwosideKeeper/LivingEntityStructure.java index b1577dd..8ac958b 100644 --- a/src/sig/plugin/TwosideKeeper/LivingEntityStructure.java +++ b/src/sig/plugin/TwosideKeeper/LivingEntityStructure.java @@ -20,7 +20,7 @@ public class LivingEntityStructure { public boolean isElite=false; public double original_movespd = 0.0d; public HashMap hitlist = new HashMap(); - public HashMap glowcolorlist = new HashMap(); + public HashMap glowcolorlist = new HashMap(); //public long lastSpiderBallThrow = 0; public BossMonster bm = null; public boolean checkedforcubes=false; @@ -83,12 +83,12 @@ public class LivingEntityStructure { } public void setGlow(Player p, GlowAPI.Color col) { - glowcolorlist.put(p, col); + glowcolorlist.put(p.getUniqueId(), col); } public void setGlobalGlow(GlowAPI.Color col) { for (Player p : Bukkit.getOnlinePlayers()) { - glowcolorlist.put(p, col); + glowcolorlist.put(p.getUniqueId(), col); } } @@ -118,9 +118,18 @@ public class LivingEntityStructure { setGlow(p,GlowAPI.Color.WHITE); } else { //No glow. - setGlow(p,null); + //setGlow(p,null); + if (glowcolorlist.containsKey(p.getUniqueId())) { + GlowAPI.setGlowing(m, null, p); + glowcolorlist.remove(p.getUniqueId()); + } + } + if (!GlowAPI.isGlowing(m, p) && glowcolorlist.containsKey(p.getUniqueId())) { + GlowAPI.setGlowing(m, glowcolorlist.get(p.getUniqueId()), p); + } else + if (GlowAPI.isGlowing(m, p) && !glowcolorlist.get(p.getUniqueId()).equals(GlowAPI.getGlowColor(m, p))) { + GlowAPI.setGlowing(m, glowcolorlist.get(p.getUniqueId()), p); } - GlowAPI.setGlowing(m, glowcolorlist.get(p), p); } } diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java index 90ed228..5aacd7a 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java @@ -8802,20 +8802,37 @@ public class TwosideKeeper extends JavaPlugin implements Listener { pe.getType().equals(PotionEffectType.WITHER) || pe.getType().equals(PotionEffectType.UNLUCK)) { hasDebuff=true; + break; } } - String bar = " "; + StringBuilder bar = new StringBuilder(Character.toString(' ')); boolean isslayer = PlayerMode.getPlayerMode(p)==PlayerMode.SLAYER; PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); double hpval = (isslayer)?pd.slayermodehp:p.getHealth(); if (isslayer) {p.setHealth(pd.slayermodehp);} - if (pcthp==100) {bar += ((isHungry)?ChatColor.BLUE:ChatColor.AQUA)+""+Math.round(hpval)+""+Character.toString((char)0x2665);} else - if (pcthp>66) {bar += ((isHungry)?ChatColor.DARK_GREEN:ChatColor.GREEN)+""+Math.round(hpval)+""+Character.toString((char)0x2665);} - else if (pcthp>33) {bar += ((isHungry)?ChatColor.GOLD:ChatColor.YELLOW)+""+Math.round(hpval)+""+Character.toString((char)0x2665);} - else {bar += ((isHungry)?ChatColor.DARK_RED:ChatColor.RED)+""+Math.round(hpval)+""+Character.toString((char)0x2665);} + if (pcthp==100) { + bar.append(((isHungry)?ChatColor.BLUE:ChatColor.AQUA)); + bar.append(Math.round(hpval)); + bar.append('\u2665'); + } else + if (pcthp>66) { + bar.append(((isHungry)?ChatColor.DARK_GREEN:ChatColor.GREEN)); + bar.append(Math.round(hpval)); + bar.append('\u2665'); + } + else if (pcthp>33) { + bar.append(((isHungry)?ChatColor.GOLD:ChatColor.YELLOW)); + bar.append(Math.round(hpval)); + bar.append('\u2665'); + } + else { + bar.append(((isHungry)?ChatColor.DARK_RED:ChatColor.RED)); + bar.append(Math.round(hpval)); + bar.append('\u2665'); + } /* if (absorptionlv>0) { @@ -8823,11 +8840,12 @@ public class TwosideKeeper extends JavaPlugin implements Listener { }*/ if (hasDebuff||isHungry||inNether) { - bar+=" "; + bar.append(' '); } if (hasDebuff) { - bar+=ChatColor.GRAY+"!"; + bar.append(ChatColor.GRAY); + bar.append('!'); } /*if (isHungry) { bar+=ChatColor.RED+""+ChatColor.BOLD+"!"; @@ -8836,18 +8854,21 @@ public class TwosideKeeper extends JavaPlugin implements Listener { /* 058D:Counter-clockwise portal * 058E:Clockwise portal */ - bar+=ChatColor.DARK_PURPLE+""+Character.toString((char)0x25CA); + bar.append(ChatColor.DARK_PURPLE); + bar.append('\u25ca'); + //bar+=ChatColor.DARK_PURPLE+""+Character.toString((char)0x25CA); //bar+=ChatColor.DARK_PURPLE+""+"�"; } else if (inEnd) { /* 058D:Counter-clockwise portal * 058E:Clockwise portal */ - bar+=ChatColor.DARK_BLUE+""+Character.toString((char)0x25CA); + bar.append(ChatColor.DARK_BLUE); + bar.append('\u25ca'); //bar+=ChatColor.DARK_PURPLE+""+"�"; } - return bar; + return bar.toString(); } diff --git a/src/sig/plugin/TwosideKeeper/runServerHeartbeat.java b/src/sig/plugin/TwosideKeeper/runServerHeartbeat.java index 8d0328d..eef5140 100644 --- a/src/sig/plugin/TwosideKeeper/runServerHeartbeat.java +++ b/src/sig/plugin/TwosideKeeper/runServerHeartbeat.java @@ -319,12 +319,17 @@ final class runServerHeartbeat implements Runnable { } private void ManagePlayerScoreboardAndHealth(Player p) { + long time=System.nanoTime(); if (!p.isDead()) {TwosideKeeper.log("Player is not dead.",5); TwosideKeeper.setPlayerMaxHealth(p);} + TwosideKeeper.HeartbeatLogger.AddEntry("==Scoreboard/Health Management - Set Player Max Health", (int)(System.nanoTime()-time));time=System.nanoTime(); if (p.getScoreboard().getTeam(p.getName().toLowerCase())==null) { p.getScoreboard().registerNewTeam(p.getName().toLowerCase()).addPlayer(p); + TwosideKeeper.HeartbeatLogger.AddEntry("==Scoreboard/Health Management - Register New Team", (int)(System.nanoTime()-time));time=System.nanoTime(); } p.getScoreboard().getTeam(p.getName().toLowerCase()).setSuffix(TwosideKeeper.createHealthbar(((p.getHealth())/p.getMaxHealth())*100,p)); + TwosideKeeper.HeartbeatLogger.AddEntry("==Scoreboard/Health Management - Set Suffix", (int)(System.nanoTime()-time));time=System.nanoTime(); p.getScoreboard().getTeam(p.getName().toLowerCase()).setPrefix(GenericFunctions.PlayerModePrefix(p)); + TwosideKeeper.HeartbeatLogger.AddEntry("==Scoreboard/Health Management - Set Prefix", (int)(System.nanoTime()-time));time=System.nanoTime(); } private void HealForSleeping(Player p, PlayerStructure pd) { @@ -589,6 +594,8 @@ final class runServerHeartbeat implements Runnable { aPlugin.API.takeTimings(3600); } TwosideKeeper.lastTimingReport=TwosideKeeper.getServerTickTime(); + GenericFunctions.logToFile("["+TwosideKeeper.getServerTickTime()+"] TPS: "+tps+"\n------------------\n"+TwosideKeeper.HeartbeatLogger.outputReport(),"logs/"+TwosideKeeper.getServerTickTime()); + aPlugin.API.discordPostFileAttachment(new File(TwosideKeeper.filesave, "logs/"+TwosideKeeper.getServerTickTime())); } if (tps<18) { GenericFunctions.logToFile("["+TwosideKeeper.getServerTickTime()+"] TPS: "+tps+"\n------------------\n"+TwosideKeeper.HeartbeatLogger.outputReport()); @@ -607,7 +614,8 @@ final class runServerHeartbeat implements Runnable { File config; config = new File(TwosideKeeper.filesave,"users/"+user+".data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); - aPlugin.DiscordMessageSender.sendPM("A storm"+((Bukkit.getWorld("world").isThundering())?" (With Thunder)":"")+" is now occuring on the server. (Day "+(int)(TwosideKeeper.getServerTickTime()/48000)+")", workable.getString("weatherwatch_user")); + //aPlugin.DiscordMessageSender.sendPM("A storm"+((Bukkit.getWorld("world").isThundering())?" (With Thunder)":"")+" is now occuring on the server. (Day "+(int)(TwosideKeeper.getServerTickTime()/48000)+")", workable.getString("weatherwatch_user")); + aPlugin.API.discordSendDM(workable.getString("weatherwatch_user"), "A storm"+((Bukkit.getWorld("world").isThundering())?" (With Thunder)":"")+" is now occuring on the server. (Day "+(int)(TwosideKeeper.getServerTickTime()/48000)+")"); } } } @@ -798,10 +806,12 @@ final class runServerHeartbeat implements Runnable { private void MaintainMonsterData() { Set data= TwosideKeeper.livingentitydata.keySet(); TwosideKeeper.log("Size: "+TwosideKeeper.livingentitydata.size(), 5); + long time = System.nanoTime(); for (UUID id : data) { LivingEntityStructure ms = TwosideKeeper.livingentitydata.get(id); if (ms.checkedforcubes) { ms.checkedforcubes=false; + TwosideKeeper.HeartbeatLogger.AddEntry("Monster Management - Magma Cube Clear", (int)(System.nanoTime()-time));time=System.nanoTime(); } if (!ms.m.isValid() || ms.m instanceof Player) { //TwosideKeeper.monsterdata.remove(data); @@ -809,15 +819,19 @@ final class runServerHeartbeat implements Runnable { TwosideKeeper.ScheduleRemoval(data, id); TwosideKeeper.ScheduleRemoval(TwosideKeeper.habitat_data.startinglocs, id); TwosideKeeper.log("Removed Monster Structure for "+id+".", 5); + TwosideKeeper.HeartbeatLogger.AddEntry("Monster Management - Removed Monster Structure Data.", (int)(System.nanoTime()-time));time=System.nanoTime(); } else { AddEliteStructureIfOneDoesNotExist(ms); + TwosideKeeper.HeartbeatLogger.AddEntry("Monster Management - Add Elite Structure", (int)(System.nanoTime()-time));time=System.nanoTime(); if (ms.GetTarget()!=null && ms.GetTarget().isValid() && !ms.GetTarget().isDead() && ms.m.hasAI()) { //Randomly move this monster a tiny bit in case they are stuck. double xdir=((ms.m.getLocation().getX()>ms.GetTarget().getLocation().getX())?-0.25:0.25)+(Math.random()/8)-(Math.random()/8); double zdir=((ms.m.getLocation().getZ()>ms.GetTarget().getLocation().getZ())?-0.25:0.25)+(Math.random()/8)-(Math.random()/8); ms.m.setVelocity(ms.m.getVelocity().add(new Vector(xdir,0,zdir))); + TwosideKeeper.HeartbeatLogger.AddEntry("Monster Management - Randomly Move this Monster", (int)(System.nanoTime()-time));time=System.nanoTime(); } ms.UpdateGlow(); + TwosideKeeper.HeartbeatLogger.AddEntry("Monster Management - Update Glow", (int)(System.nanoTime()-time));time=System.nanoTime(); } } } @@ -904,7 +918,7 @@ final class runServerHeartbeat implements Runnable { } TwosideKeeper.log_messages.clear(); if (finalstring.length()>0) { - DiscordMessageSender.sendToSpam(finalstring.toString()); + //DiscordMessageSender.sendToSpam(finalstring.toString()); } }