diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index 39674df..bae7cb4 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/sig/plugin/TwosideKeeper/EliteMonster.java b/src/sig/plugin/TwosideKeeper/EliteMonster.java index 6fa9cfd..6933cf6 100644 --- a/src/sig/plugin/TwosideKeeper/EliteMonster.java +++ b/src/sig/plugin/TwosideKeeper/EliteMonster.java @@ -113,7 +113,7 @@ public class EliteMonster { weakenTeam(); retargetInAir(); destroyLiquids(2); - reapplyGlow(); + getGlow(); } } @@ -290,17 +290,16 @@ public class EliteMonster { ChargeZombie.BreakBlocksAroundArea(2, m.getLocation()); } - private void reapplyGlow() { - if (last_applyglow_time+GLOW_TIME<=TwosideKeeper.getServerTickTime()) { - GlowAPI.Color col = GlowAPI.Color.DARK_PURPLE; - if (m.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE)) { - col = GlowAPI.Color.YELLOW; - } - if (storingenergy) { - col = GlowAPI.Color.GREEN; - } - GenericFunctions.setGlowing(m, col); + public GlowAPI.Color getGlow() { + GlowAPI.Color col = GlowAPI.Color.DARK_PURPLE; + if (m.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE)) { + col = GlowAPI.Color.YELLOW; + } + if (storingenergy) { + col = GlowAPI.Color.GREEN; } + //GenericFunctions.setGlowing(m, col); + return col; } private void destroyLiquids(int radius) { @@ -604,7 +603,7 @@ public class EliteMonster { for (int x=-radius;xSetting a monster with Difficulty "+md.name()+" w/"+m.getHealth()+"/"+m.getMaxHealth()+" HP to a Leader.",5); } else { m.setMaxHealth(m.getMaxHealth()*2.0); @@ -767,10 +769,11 @@ public class MonsterController { if(isZombieLeader(m)) { m.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,8)); - GlowAPI.setGlowing(m, Color.DARK_RED, Bukkit.getOnlinePlayers()); m.setMaxHealth(1200); //Target is 1200 HP. m.setHealth(m.getMaxHealth()); - MonsterStructure.getMonsterStructure(m).SetLeader(true); + MonsterStructure ms = MonsterStructure.getMonsterStructure(m); + ms.SetLeader(true); + ms.UpdateGlow(); TwosideKeeper.log("->Setting a monster with Difficulty "+md.name()+" w/"+m.getHealth()+"/"+m.getMaxHealth()+" HP to a Leader.",5); } else { m.setMaxHealth(m.getMaxHealth()*3.0); @@ -799,7 +802,9 @@ public class MonsterController { if(isZombieLeader(m)) { m.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,8)); - GlowAPI.setGlowing(m, Color.DARK_RED, Bukkit.getOnlinePlayers()); + MonsterStructure ms = MonsterStructure.getMonsterStructure(m); + ms.SetLeader(true); + ms.UpdateGlow(); m.setMaxHealth(1600); //Target is 1600 HP. m.setHealth(m.getMaxHealth()); MonsterStructure.getMonsterStructure(m).SetLeader(true); @@ -819,7 +824,6 @@ public class MonsterController { //m.setCustomNameVisible(true); m.setMaxHealth(4800); m.setHealth(m.getMaxHealth()); - GlowAPI.setGlowing(m, Color.DARK_PURPLE, Bukkit.getOnlinePlayers()); if (isAllowedToEquipItems(m)) { m.getEquipment().clear(); RandomizeEquipment(m,4); @@ -832,7 +836,9 @@ public class MonsterController { } m.setCustomNameVisible(true); m.setRemoveWhenFarAway(false); - MonsterStructure.getMonsterStructure(m).SetElite(true); + MonsterStructure ms = MonsterStructure.getMonsterStructure(m); + ms.SetElite(true); + ms.UpdateGlow(); m.getAttribute(Attribute.GENERIC_FOLLOW_RANGE).setBaseValue(72.0); }break; default: { @@ -846,11 +852,12 @@ public class MonsterController { if(isZombieLeader(m)) { m.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,8)); - GlowAPI.setGlowing(m, Color.DARK_RED, Bukkit.getOnlinePlayers()); m.setMaxHealth(400); m.setHealth(m.getMaxHealth()); m.setCustomName("Zombie Leader"); - MonsterStructure.getMonsterStructure(m).SetLeader(true); + MonsterStructure ms = MonsterStructure.getMonsterStructure(m); + ms.SetLeader(true); + ms.UpdateGlow(); TwosideKeeper.log("->Setting a monster with Difficulty "+md.name()+" w/"+m.getHealth()+"/"+m.getMaxHealth()+" HP to a Leader.",5); } else { m.setMaxHealth(m.getMaxHealth()*1.0); @@ -873,10 +880,11 @@ public class MonsterController { SetupCustomName(ChatColor.DARK_BLUE+""+ChatColor.MAGIC+"End",m); if(isZombieLeader(m)) { - GlowAPI.setGlowing(m, Color.DARK_RED, Bukkit.getOnlinePlayers()); m.setMaxHealth(32000); //Target is 1600 HP. m.setHealth(m.getMaxHealth()); - MonsterStructure.getMonsterStructure(m).SetLeader(true); + MonsterStructure ms = MonsterStructure.getMonsterStructure(m); + ms.SetLeader(true); + ms.UpdateGlow(); TwosideKeeper.log("->Setting a monster with Difficulty "+md.name()+" w/"+m.getHealth()+"/"+m.getMaxHealth()+" HP to a Leader.",5); } else { m.setMaxHealth(m.getMaxHealth()*80.0); diff --git a/src/sig/plugin/TwosideKeeper/MonsterStructure.java b/src/sig/plugin/TwosideKeeper/MonsterStructure.java index 4732bdc..348f5f5 100644 --- a/src/sig/plugin/TwosideKeeper/MonsterStructure.java +++ b/src/sig/plugin/TwosideKeeper/MonsterStructure.java @@ -3,8 +3,13 @@ package sig.plugin.TwosideKeeper; import java.util.HashMap; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.inventivetalent.glow.GlowAPI; + +import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; public class MonsterStructure { public LivingEntity target; @@ -13,6 +18,7 @@ public class MonsterStructure { public boolean isLeader=false; public boolean isElite=false; public HashMap hitlist = new HashMap(); + public HashMap glowcolorlist = new HashMap(); public MonsterStructure(Monster m) { target=null; @@ -62,6 +68,48 @@ public class MonsterStructure { return this.isElite; } + public void setGlow(Player p, GlowAPI.Color col) { + glowcolorlist.put(p, col); + GlowAPI.setGlowing(m, col, p); + } + + public void setGlobalGlow(GlowAPI.Color col) { + for (Player p : Bukkit.getOnlinePlayers()) { + glowcolorlist.put(p, col); + GlowAPI.setGlowing(m, col, p); + } + } + + public void UpdateGlow() { + //Updates the glow color for all players. We base it on default statuses here. CALL THIS INSTEAD OF + // SETTING THE GLOW DIRECTLY ANYMORE! + for (Player p : Bukkit.getOnlinePlayers()) { + if (GenericFunctions.isSuppressed(m)) { + setGlow(p,GlowAPI.Color.BLACK); + } else + if (getLeader() || GenericFunctions.isBossMonster(m)) { + setGlow(p,GlowAPI.Color.DARK_RED); + } else + if (getElite()) { + boolean handled=false; + for (EliteMonster em : TwosideKeeper.elitemonsters) { + if (em.getMonster().equals(m)) { + setGlow(p,em.getGlow()); + } + } + if (!handled) { + setGlow(p,GlowAPI.Color.DARK_PURPLE); + } + } else + if (GenericFunctions.isIsolatedTarget(m, p)) { + setGlow(p,GlowAPI.Color.WHITE); + } else { + //No glow. + setGlow(p,null); + } + } + } + //Either gets a monster structure that exists or creates a new one. public static MonsterStructure getMonsterStructure(Monster m) { UUID id = m.getUniqueId(); diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java index 6a35151..180fb41 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java @@ -137,7 +137,6 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import org.inventivetalent.glow.GlowAPI; -import aPlugin.DiscordMessageSender; import aPlugin.API.Chests; import events.PluginLoadEvent; import net.md_5.bungee.api.chat.ClickEvent; @@ -283,435 +282,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } - private final class runServerHeartbeat implements Runnable { - @SuppressWarnings("deprecation") - public void run(){ - log("Server time passed: "+(Bukkit.getWorld("world").getFullTime()-STARTTIME)+". New Server Time: "+(Bukkit.getWorld("world").getFullTime()-STARTTIME+SERVERTICK),5); - //Bukkit.getWorld("world").setFullTime(Bukkit.getWorld("world").getFullTime()-10); //LEGACY CODE. - adjustServerTime(10); - //WORK IN PROGRESS: Lamp updating code TO GO HERE. - - sendAllLoggedMessagesToSpam(); - - //SAVE SERVER SETTINGS. - if (getServerTickTime()-LASTSERVERCHECK>=SERVERCHECKERTICKS) { //15 MINUTES (DEFAULT) - saveOurData(); - - //Advertisement messages could go here. - //MOTD: "Thanks for playing on Sig's Minecraft!\n*bCheck out http://z-gamers.net/mc for update info!\n*aReport any bugs you find at http://zgamers.domain.com/mc/" - getMOTD(); - getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('*', MOTD)); - habitat_data.increaseHabitationLevels(); - habitat_data.startinglocs.clear(); - for (int i=0;i=12000) { - Collection players = getServer().getOnlinePlayers(); - //Count the number of players sleeping. Compare to "sleepingplayers" count. - log("[DEBUG] Time: "+Bukkit.getWorld("world").getTime()+" Full Time: "+Bukkit.getWorld("world").getFullTime() + " SERVERTICKTIME: "+getServerTickTime(),4); - //This functionality only makes sense when two or more players are on. - int sleeping=0; - for (Player p : players) { - if (p.isSleeping()) { - if (PlayerMode.getPlayerMode(p)==PlayerMode.SLAYER) { - PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); - pd.slayermodehp=p.getMaxHealth(); - } - p.setHealth(p.getMaxHealth()); - sleeping++; - } - } - if (sleepingPlayers!=sleeping) { - sleepingPlayers=sleeping; - if (players.size()>1) { - getServer().broadcastMessage(ChatColor.GOLD+""+sleepingPlayers+" Player"+(sleepingPlayers!=1?"s are":" is")+" in bed "+ChatColor.WHITE+"("+sleepingPlayers+"/"+(players.size()/2)+")"); - } - } - if (sleepingPlayers>=Math.max(players.size()/2,1)) { - //Make it the next day. - if (players.size()>1) { - getServer().broadcastMessage(ChatColor.GOLD+"Enough Players sleeping! It's now morning!"); - } - /*Bukkit.getWorld("world").setFullTime(Bukkit.getWorld("world").getFullTime()+10); - - SERVERTICK=getServerTickTime();*/ - long temptime = Bukkit.getWorld("world").getFullTime(); - Bukkit.getWorld("world").setTime(0); - time_passed+=temptime-Bukkit.getWorld("world").getFullTime(); - Bukkit.getWorld("world").setThundering(false); - /* - STARTTIME=Bukkit.getWorld("world").getFullTime(); - LASTSERVERCHECK=getServerTickTime();*/ - //Make sure we keep SERVERTICK in check. - sleepingPlayers=0; - } - } - - if (getServerTickTime()-LastClearStructureTime>=100) { - //Perform a clear of Monster Structure. - for(UUID id : monsterdata.keySet()) { - MonsterStructure mon = monsterdata.get(id); - Monster m = mon.m; - if (!m.isValid()) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - () -> { - monsterdata.remove(id); - log("Removed one from Structure",5); - }, 1); - } - if (mon.isLeader || MonsterController.isZombieLeader(m)) { - //Make it glow red. - GenericFunctions.setGlowing(m, GlowAPI.Color.DARK_RED); - } - if (mon.isElite || MonsterController.getMonsterDifficulty(m)==MonsterDifficulty.ELITE) { - //Make it glow dark purple. - GenericFunctions.setGlowing(m, GlowAPI.Color.DARK_PURPLE); - boolean hasstruct = false; - for (EliteMonster em : elitemonsters) { - if (em.m.equals(m)) { - hasstruct=true; - } - } - if (!hasstruct) { - elitemonsters.add(new EliteMonster(m)); - } - } - } - } - - //See if each player needs to regenerate their health. - for (Player p : Bukkit.getOnlinePlayers()) { - if (!p.isDead()) { - PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); - GenericFunctions.RemoveNewDebuffs(p); - - if (p.isSprinting() && pd.lastsprintcheck+(20*5)4.317) { - pd.velocity/=2; - } else { - pd.velocity=0; - } - if (pd.highwinder && pd.target!=null && !pd.target.isDead()) { - aPlugin.API.sendActionBarMessage(p, drawVelocityBar(pd.velocity,pd.highwinderdmg)); - } - if (pd.target!=null && !pd.target.isDead() && pd.target.getLocation().getWorld().equals(p.getWorld()) && pd.target.getLocation().distanceSquared(p.getLocation())>256) { - pd.target=null; - } - - if (pd.lasthittarget+20*15<=getServerTickTime() && pd.storedbowxp>0 && GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand()) && - p.getEquipment().getItemInMainHand().getType()==Material.BOW) { - AwakenedArtifact.addPotentialEXP(p.getEquipment().getItemInMainHand(), pd.storedbowxp, p); - TwosideKeeper.log("Added "+pd.storedbowxp+" Artifact XP", 2); - pd.storedbowxp=0; - } - - if (p.getFireTicks()>0 && p.hasPotionEffect(PotionEffectType.FIRE_RESISTANCE)) { - int duration = GenericFunctions.getPotionEffectDuration(PotionEffectType.FIRE_RESISTANCE, p); - int lv = GenericFunctions.getPotionEffectLevel(PotionEffectType.FIRE_RESISTANCE, p); - if (lv>10) {lv=10;} - GenericFunctions.logAndApplyPotionEffectToPlayer(PotionEffectType.FIRE_RESISTANCE, duration-(20*(10-lv)), lv, p, true); - } - - if (GenericFunctions.hasStealth(p)) {GenericFunctions.DamageRandomTool(p);} - - p.getAttribute(Attribute.GENERIC_ARMOR).setBaseValue(20*(1.0d-CustomDamage.CalculateDamageReduction(1,p,null))+subtractVanillaArmorBar(p.getEquipment().getArmorContents())); - - ItemStack[] equips = p.getEquipment().getArmorContents(); - - if (pd.last_regen_time+HEALTH_REGENERATION_RATE<=getServerTickTime()) { - pd.last_regen_time=getServerTickTime(); - //See if this player needs to be healed. - if (p!=null && - !p.isDead() && //Um, don't heal them if they're dead...That's just weird. - p.getHealth()=16) { - - if (PlayerMode.getPlayerMode(p)!=PlayerMode.SLAYER || pd.lastcombat+(20*60)p.getMaxHealth())?p.getMaxHealth():p.getHealth()+totalregen); - - if (PlayerMode.getPlayerMode(p)==PlayerMode.SLAYER) { - pd.slayermodehp=p.getHealth(); - } - } - } - } - - if (p.getWorld().getName().equalsIgnoreCase("world_the_end")) { - if (pd.endnotification+72000=0 && p.getLocation().getY()<=255 && p.getLocation().add(0,0,0).getBlock().getLightLevel()<=4) { - GenericFunctions.logAndApplyPotionEffectToPlayer(PotionEffectType.SPEED,20,1,p); - } - } - if (ArtifactAbility.containsEnchantment(ArtifactAbility.SHADOWWALKER, p.getEquipment().getItemInMainHand()) && - p.isOnGround() && p.getLocation().getY()>=0 && p.getLocation().getY()<=255 && p.getLocation().add(0,0,0).getBlock().getLightLevel()<=4) { - GenericFunctions.logAndApplyPotionEffectToPlayer(PotionEffectType.SPEED,20,1,p); - //log("Apply speed. The light level here is "+p.getLocation().add(0,-1,0).getBlock().getLightLevel(),2); - } - - if (ArtifactAbility.containsEnchantment(ArtifactAbility.COMBO, p.getEquipment().getItemInMainHand()) && - pd.last_swordhit+40 mobs = GenericFunctions.getNearbyMobs(p.getLocation(), 16); - for (Monster m : mobs) { - if (!GenericFunctions.isIsolatedTarget(m,p) && - !GenericFunctions.isSpecialGlowMonster(m)) {GlowAPI.setGlowing(m, GlowAPI.Color.WHITE, p);} - if (GenericFunctions.isIsolatedTarget(m,p) && - !GenericFunctions.isSpecialGlowMonster(m) && - GenericFunctions.GetNearbyMonsterCount(m, 8)>0) { - GlowAPI.setGlowing(m, false, p); - } - } - } else { - List mobs = GenericFunctions.getNearbyMobs(p.getLocation(), 16); - for (Monster m : mobs) { - if (GenericFunctions.isIsolatedTarget(m,p) && - !GenericFunctions.isSpecialGlowMonster(m)) {GlowAPI.setGlowing(m, false, p);} - } - } - - GenericFunctions.AutoRepairItems(p); - } - } - - PartyManager.SetupParties(); - - TwosideSpleefGames.TickEvent(); - } - - private void randomlyAggroNearbyEndermen(Player p) { - List ents = GenericFunctions.getNearbyMobs(p.getLocation(), 16); - for (Monster m : ents) { - if (Math.random()<=0.05 && !m.hasPotionEffect(PotionEffectType.GLOWING)) { - m.setTarget(p); - } - } - } - - private void playEndWarningNotification(Player p) { - Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { - @Override - public void run() { - p.sendMessage(ChatColor.GOLD+"A Mysterious Entity glares at you..."); - } - },1); - Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { - @Override - public void run() { - p.sendMessage(ChatColor.BLUE+" \"You DO NOT BELONG HERE.\""); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SCREAM, 1.0f, 1.0f); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_AMBIENT, 1.0f, 1.0f); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SHOOT, 1.0f, 1.0f); - } - },20); - Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { - @Override - public void run() { - p.playSound(p.getLocation().add(0,20,0), Sound.ENTITY_GHAST_WARN, 1.0f, 1.0f); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_AMBIENT, 1.0f, 1.0f); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SHOOT, 1.0f, 1.0f); - } - },23); - Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { - @Override - public void run() { - p.playSound(p.getLocation().add(-10,0,-5), Sound.ENTITY_GHAST_SCREAM, 1.0f, 1.0f); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_AMBIENT, 1.0f, 1.0f); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SHOOT, 1.0f, 1.0f); - } - },27); - Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { - @Override - public void run() { - p.playSound(p.getLocation().add(-10,0,-5), Sound.ENTITY_GHAST_SCREAM, 1.0f, 1.0f); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_AMBIENT, 1.0f, 1.0f); - p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SHOOT, 1.0f, 1.0f); - } - },30); - Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { - @Override - public void run() { - p.sendMessage(ChatColor.RED+"You cannot identify The End properly!"); - } - },90); - } - - private void sendAllLoggedMessagesToSpam() { - StringBuilder finalstring = new StringBuilder(); - for (String msg : TwosideKeeper.log_messages) { - finalstring.append(msg+"\n"); - } - TwosideKeeper.log_messages.clear(); - if (finalstring.length()>0) { - DiscordMessageSender.sendToSpam(finalstring.toString()); - } - } - - private double subtractVanillaArmorBar(ItemStack[] armorContents) { - double lostamt = 0.0d; - for (ItemStack equip : armorContents) { - if (equip!=null && - equip.getType()!=Material.AIR) { - switch (equip.getType()) { - case LEATHER_HELMET:{ - lostamt-=1; - }break; - case LEATHER_CHESTPLATE:{ - lostamt-=3; - }break; - case LEATHER_LEGGINGS:{ - lostamt-=2; - }break; - case LEATHER_BOOTS:{ - lostamt-=1; - }break; - case GOLD_HELMET:{ - lostamt-=2; - }break; - case GOLD_CHESTPLATE:{ - lostamt-=5; - }break; - case GOLD_LEGGINGS:{ - lostamt-=3; - }break; - case GOLD_BOOTS:{ - lostamt-=1; - }break; - case CHAINMAIL_HELMET:{ - lostamt-=2; - }break; - case CHAINMAIL_CHESTPLATE:{ - lostamt-=5; - }break; - case CHAINMAIL_LEGGINGS:{ - lostamt-=4; - }break; - case CHAINMAIL_BOOTS:{ - lostamt-=1; - }break; - case IRON_HELMET:{ - lostamt-=2; - }break; - case IRON_CHESTPLATE:{ - lostamt-=6; - }break; - case IRON_LEGGINGS:{ - lostamt-=5; - }break; - case IRON_BOOTS:{ - lostamt-=2; - }break; - case DIAMOND_HELMET:{ - lostamt-=3; - }break; - case DIAMOND_CHESTPLATE:{ - lostamt-=8; - }break; - case DIAMOND_LEGGINGS:{ - lostamt-=6; - }break; - case DIAMOND_BOOTS:{ - lostamt-=3; - }break; - default:{ - - } - } - } - } - return lostamt; - } - } - private final class ReapplyAbsorptionHeartsFromSet implements Runnable { public void run(){ for (Player p : Bukkit.getOnlinePlayers()) { @@ -799,9 +369,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { for (Entity e : suppressed_entities) { if (e==null || !e.isValid() || GenericFunctions.getSuppressionTime(e)<=0) { - if (GlowAPI.isGlowing(e, Bukkit.getOnlinePlayers(),false)) { - GlowAPI.setGlowing(e, null, Bukkit.getOnlinePlayers()); - } ScheduleRemoval(suppressed_entities,e); } } @@ -1172,7 +739,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { getServer().getScheduler().scheduleSyncRepeatingTask(this, new ReapplyAbsorptionHeartsFromSet(),0l,600l); //This is the constant timing method. - getServer().getScheduler().scheduleSyncRepeatingTask(this, new runServerHeartbeat(), 20l, 20l); + getServer().getScheduler().scheduleSyncRepeatingTask(this, new runServerHeartbeat(this), 20l, 20l); } @Override @@ -4649,10 +4216,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } } - if ((ev.getEntity() instanceof Monster) && GenericFunctions.isBossMonster((Monster)ev.getEntity())) { - Monster m = (Monster)ev.getEntity(); - GlowAPI.setGlowing(m, GlowAPI.Color.DARK_RED, Bukkit.getOnlinePlayers()); - } if (ev.getTarget() instanceof Player && ev.getEntity() instanceof Monster) { Player p = (Player)ev.getTarget(); diff --git a/src/sig/plugin/TwosideKeeper/runServerHeartbeat.java b/src/sig/plugin/TwosideKeeper/runServerHeartbeat.java new file mode 100644 index 0000000..1e726b5 --- /dev/null +++ b/src/sig/plugin/TwosideKeeper/runServerHeartbeat.java @@ -0,0 +1,467 @@ +package sig.plugin.TwosideKeeper; + +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffectType; +import org.inventivetalent.glow.GlowAPI; + +import aPlugin.DiscordMessageSender; +import sig.plugin.TwosideKeeper.HelperStructures.ArtifactAbility; +import sig.plugin.TwosideKeeper.HelperStructures.BankSession; +import sig.plugin.TwosideKeeper.HelperStructures.ItemSet; +import sig.plugin.TwosideKeeper.HelperStructures.MonsterDifficulty; +import sig.plugin.TwosideKeeper.HelperStructures.PlayerMode; +import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; + +final class runServerHeartbeat implements Runnable { + /** + * + */ + private final TwosideKeeper ServerHeartbeat; + + /** + * @param twosideKeeper + */ + runServerHeartbeat(TwosideKeeper twosideKeeper) { + ServerHeartbeat = twosideKeeper; + } + + @SuppressWarnings("deprecation") + public void run(){ + TwosideKeeper.log("Server time passed: "+(Bukkit.getWorld("world").getFullTime()-TwosideKeeper.STARTTIME)+". New Server Time: "+(Bukkit.getWorld("world").getFullTime()-TwosideKeeper.STARTTIME+TwosideKeeper.SERVERTICK),5); + //Bukkit.getWorld("world").setFullTime(Bukkit.getWorld("world").getFullTime()-10); //LEGACY CODE. + TwosideKeeper.adjustServerTime(10); + //WORK IN PROGRESS: Lamp updating code TO GO HERE. + + sendAllLoggedMessagesToSpam(); + + //SAVE SERVER SETTINGS. + if (TwosideKeeper.getServerTickTime()-TwosideKeeper.LASTSERVERCHECK>=TwosideKeeper.SERVERCHECKERTICKS) { //15 MINUTES (DEFAULT) + ServerHeartbeat.saveOurData(); + + //Advertisement messages could go here. + //MOTD: "Thanks for playing on Sig's Minecraft!\n*bCheck out http://z-gamers.net/mc for update info!\n*aReport any bugs you find at http://zgamers.domain.com/mc/" + ServerHeartbeat.getMOTD(); + ServerHeartbeat.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('*', TwosideKeeper.MOTD)); + TwosideKeeper.habitat_data.increaseHabitationLevels(); + TwosideKeeper.habitat_data.startinglocs.clear(); + for (int i=0;i=12000) { + Collection players = ServerHeartbeat.getServer().getOnlinePlayers(); + //Count the number of players sleeping. Compare to "sleepingplayers" count. + TwosideKeeper.log("[DEBUG] Time: "+Bukkit.getWorld("world").getTime()+" Full Time: "+Bukkit.getWorld("world").getFullTime() + " SERVERTICKTIME: "+TwosideKeeper.getServerTickTime(),4); + //This functionality only makes sense when two or more players are on. + int sleeping=0; + for (Player p : players) { + if (p.isSleeping()) { + if (PlayerMode.getPlayerMode(p)==PlayerMode.SLAYER) { + PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); + pd.slayermodehp=p.getMaxHealth(); + } + p.setHealth(p.getMaxHealth()); + sleeping++; + } + } + if (ServerHeartbeat.sleepingPlayers!=sleeping) { + ServerHeartbeat.sleepingPlayers=sleeping; + if (players.size()>1) { + ServerHeartbeat.getServer().broadcastMessage(ChatColor.GOLD+""+ServerHeartbeat.sleepingPlayers+" Player"+(ServerHeartbeat.sleepingPlayers!=1?"s are":" is")+" in bed "+ChatColor.WHITE+"("+ServerHeartbeat.sleepingPlayers+"/"+(players.size()/2)+")"); + } + } + if (ServerHeartbeat.sleepingPlayers>=Math.max(players.size()/2,1)) { + //Make it the next day. + if (players.size()>1) { + ServerHeartbeat.getServer().broadcastMessage(ChatColor.GOLD+"Enough Players sleeping! It's now morning!"); + } + /*Bukkit.getWorld("world").setFullTime(Bukkit.getWorld("world").getFullTime()+10); + + SERVERTICK=getServerTickTime();*/ + long temptime = Bukkit.getWorld("world").getFullTime(); + Bukkit.getWorld("world").setTime(0); + TwosideKeeper.time_passed+=temptime-Bukkit.getWorld("world").getFullTime(); + Bukkit.getWorld("world").setThundering(false); + /* + STARTTIME=Bukkit.getWorld("world").getFullTime(); + LASTSERVERCHECK=getServerTickTime();*/ + //Make sure we keep SERVERTICK in check. + ServerHeartbeat.sleepingPlayers=0; + } + } + + //See if each player needs to regenerate their health. + for (Player p : Bukkit.getOnlinePlayers()) { + if (!p.isDead()) { + PlayerStructure pd = (PlayerStructure)TwosideKeeper.playerdata.get(p.getUniqueId()); + GenericFunctions.RemoveNewDebuffs(p); + + if (p.isSprinting() && pd.lastsprintcheck+(20*5)4.317) { + pd.velocity/=2; + } else { + pd.velocity=0; + } + if (pd.highwinder && pd.target!=null && !pd.target.isDead()) { + aPlugin.API.sendActionBarMessage(p, TwosideKeeper.drawVelocityBar(pd.velocity,pd.highwinderdmg)); + } + if (pd.target!=null && !pd.target.isDead() && pd.target.getLocation().getWorld().equals(p.getWorld()) && pd.target.getLocation().distanceSquared(p.getLocation())>256) { + pd.target=null; + } + + if (pd.lasthittarget+20*15<=TwosideKeeper.getServerTickTime() && pd.storedbowxp>0 && GenericFunctions.isArtifactEquip(p.getEquipment().getItemInMainHand()) && + p.getEquipment().getItemInMainHand().getType()==Material.BOW) { + AwakenedArtifact.addPotentialEXP(p.getEquipment().getItemInMainHand(), pd.storedbowxp, p); + TwosideKeeper.log("Added "+pd.storedbowxp+" Artifact XP", 2); + pd.storedbowxp=0; + } + + if (p.getFireTicks()>0 && p.hasPotionEffect(PotionEffectType.FIRE_RESISTANCE)) { + int duration = GenericFunctions.getPotionEffectDuration(PotionEffectType.FIRE_RESISTANCE, p); + int lv = GenericFunctions.getPotionEffectLevel(PotionEffectType.FIRE_RESISTANCE, p); + if (lv>10) {lv=10;} + GenericFunctions.logAndApplyPotionEffectToPlayer(PotionEffectType.FIRE_RESISTANCE, duration-(20*(10-lv)), lv, p, true); + } + + if (GenericFunctions.hasStealth(p)) {GenericFunctions.DamageRandomTool(p);} + + p.getAttribute(Attribute.GENERIC_ARMOR).setBaseValue(20*(1.0d-CustomDamage.CalculateDamageReduction(1,p,null))+subtractVanillaArmorBar(p.getEquipment().getArmorContents())); + + ItemStack[] equips = p.getEquipment().getArmorContents(); + + if (pd.last_regen_time+TwosideKeeper.HEALTH_REGENERATION_RATE<=TwosideKeeper.getServerTickTime()) { + pd.last_regen_time=TwosideKeeper.getServerTickTime(); + //See if this player needs to be healed. + if (p!=null && + !p.isDead() && //Um, don't heal them if they're dead...That's just weird. + p.getHealth()=16) { + + if (PlayerMode.getPlayerMode(p)!=PlayerMode.SLAYER || pd.lastcombat+(20*60)p.getMaxHealth())?p.getMaxHealth():p.getHealth()+totalregen); + + if (PlayerMode.getPlayerMode(p)==PlayerMode.SLAYER) { + pd.slayermodehp=p.getHealth(); + } + } + } + } + + if (p.getWorld().getName().equalsIgnoreCase("world_the_end")) { + if (pd.endnotification+72000=0 && p.getLocation().getY()<=255 && p.getLocation().add(0,0,0).getBlock().getLightLevel()<=4) { + GenericFunctions.logAndApplyPotionEffectToPlayer(PotionEffectType.SPEED,20,1,p); + } + } + if (ArtifactAbility.containsEnchantment(ArtifactAbility.SHADOWWALKER, p.getEquipment().getItemInMainHand()) && + p.isOnGround() && p.getLocation().getY()>=0 && p.getLocation().getY()<=255 && p.getLocation().add(0,0,0).getBlock().getLightLevel()<=4) { + GenericFunctions.logAndApplyPotionEffectToPlayer(PotionEffectType.SPEED,20,1,p); + //log("Apply speed. The light level here is "+p.getLocation().add(0,-1,0).getBlock().getLightLevel(),2); + } + + if (ArtifactAbility.containsEnchantment(ArtifactAbility.COMBO, p.getEquipment().getItemInMainHand()) && + pd.last_swordhit+40 mobs = GenericFunctions.getNearbyMobs(p.getLocation(), 16); + for (Monster m : mobs) { + if (!GenericFunctions.isIsolatedTarget(m,p) && + !GenericFunctions.isSpecialGlowMonster(m) && + m.getLocation().distanceSquared(p.getLocation())<196) {GlowAPI.setGlowing(m, GlowAPI.Color.WHITE, p);} + if (GenericFunctions.isIsolatedTarget(m,p) && + !GenericFunctions.isSpecialGlowMonster(m) && + GenericFunctions.GetNearbyMonsterCount(m, 8)>0) { + GlowAPI.setGlowing(m, false, p); + } + }*/ + } else { + /*List mobs = GenericFunctions.getNearbyMobs(p.getLocation(), 16); + for (Monster m : mobs) { + if (GenericFunctions.isIsolatedTarget(m,p) && + !GenericFunctions.isSpecialGlowMonster(m)) {GlowAPI.setGlowing(m, false, p);} + }*/ + } + + GenericFunctions.AutoRepairItems(p); + } + } + + MaintainMonsterData(); + + PartyManager.SetupParties(); + + TwosideKeeper.TwosideSpleefGames.TickEvent(); + } + + private void MaintainMonsterData() { + Set data= TwosideKeeper.monsterdata.keySet(); + for (UUID id : data) { + MonsterStructure ms = TwosideKeeper.monsterdata.get(id); + if (ms.m==null || !ms.m.isValid()) { + TwosideKeeper.monsterdata.remove(data); + TwosideKeeper.log("Removed Monster Structure for "+id+". New Size: "+TwosideKeeper.monsterdata.size(), 5); + } else { + AddEliteStructureIfOneDoesNotExist(ms); + ms.UpdateGlow(); + } + } + } + + public void AddEliteStructureIfOneDoesNotExist(MonsterStructure ms) { + if (ms.isElite || MonsterController.getMonsterDifficulty(ms.m)==MonsterDifficulty.ELITE) { + //Make it glow dark purple. + //GenericFunctions.setGlowing(m, GlowAPI.Color.DARK_PURPLE); + boolean hasstruct = false; + for (EliteMonster em : TwosideKeeper.elitemonsters) { + if (em.m.equals(ms.m)) { + hasstruct=true; + } + } + if (!hasstruct) { + TwosideKeeper.elitemonsters.add(new EliteMonster(ms.m)); + } + } + } + + private void randomlyAggroNearbyEndermen(Player p) { + List ents = GenericFunctions.getNearbyMobs(p.getLocation(), 16); + for (Monster m : ents) { + if (Math.random()<=0.05 && !m.hasPotionEffect(PotionEffectType.GLOWING)) { + m.setTarget(p); + } + } + } + + private void playEndWarningNotification(Player p) { + Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { + @Override + public void run() { + p.sendMessage(ChatColor.GOLD+"A Mysterious Entity glares at you..."); + } + },1); + Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { + @Override + public void run() { + p.sendMessage(ChatColor.BLUE+" \"You DO NOT BELONG HERE.\""); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SCREAM, 1.0f, 1.0f); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_AMBIENT, 1.0f, 1.0f); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SHOOT, 1.0f, 1.0f); + } + },20); + Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { + @Override + public void run() { + p.playSound(p.getLocation().add(0,20,0), Sound.ENTITY_GHAST_WARN, 1.0f, 1.0f); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_AMBIENT, 1.0f, 1.0f); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SHOOT, 1.0f, 1.0f); + } + },23); + Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { + @Override + public void run() { + p.playSound(p.getLocation().add(-10,0,-5), Sound.ENTITY_GHAST_SCREAM, 1.0f, 1.0f); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_AMBIENT, 1.0f, 1.0f); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SHOOT, 1.0f, 1.0f); + } + },27); + Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { + @Override + public void run() { + p.playSound(p.getLocation().add(-10,0,-5), Sound.ENTITY_GHAST_SCREAM, 1.0f, 1.0f); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_AMBIENT, 1.0f, 1.0f); + p.playSound(p.getLocation(), Sound.ENTITY_GHAST_SHOOT, 1.0f, 1.0f); + } + },30); + Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { + @Override + public void run() { + p.sendMessage(ChatColor.RED+"You cannot identify The End properly!"); + } + },90); + } + + private void sendAllLoggedMessagesToSpam() { + StringBuilder finalstring = new StringBuilder(); + for (String msg : TwosideKeeper.log_messages) { + finalstring.append(msg+"\n"); + } + TwosideKeeper.log_messages.clear(); + if (finalstring.length()>0) { + DiscordMessageSender.sendToSpam(finalstring.toString()); + } + } + + private double subtractVanillaArmorBar(ItemStack[] armorContents) { + double lostamt = 0.0d; + for (ItemStack equip : armorContents) { + if (equip!=null && + equip.getType()!=Material.AIR) { + switch (equip.getType()) { + case LEATHER_HELMET:{ + lostamt-=1; + }break; + case LEATHER_CHESTPLATE:{ + lostamt-=3; + }break; + case LEATHER_LEGGINGS:{ + lostamt-=2; + }break; + case LEATHER_BOOTS:{ + lostamt-=1; + }break; + case GOLD_HELMET:{ + lostamt-=2; + }break; + case GOLD_CHESTPLATE:{ + lostamt-=5; + }break; + case GOLD_LEGGINGS:{ + lostamt-=3; + }break; + case GOLD_BOOTS:{ + lostamt-=1; + }break; + case CHAINMAIL_HELMET:{ + lostamt-=2; + }break; + case CHAINMAIL_CHESTPLATE:{ + lostamt-=5; + }break; + case CHAINMAIL_LEGGINGS:{ + lostamt-=4; + }break; + case CHAINMAIL_BOOTS:{ + lostamt-=1; + }break; + case IRON_HELMET:{ + lostamt-=2; + }break; + case IRON_CHESTPLATE:{ + lostamt-=6; + }break; + case IRON_LEGGINGS:{ + lostamt-=5; + }break; + case IRON_BOOTS:{ + lostamt-=2; + }break; + case DIAMOND_HELMET:{ + lostamt-=3; + }break; + case DIAMOND_CHESTPLATE:{ + lostamt-=8; + }break; + case DIAMOND_LEGGINGS:{ + lostamt-=6; + }break; + case DIAMOND_BOOTS:{ + lostamt-=3; + }break; + default:{ + + } + } + } + } + return lostamt; + } +} \ No newline at end of file