Despawn mounts on chunk unload and clean up some formatting

This commit is contained in:
AlexTheCoder 2017-07-17 13:32:27 -04:00
parent 5e70ff8471
commit d5355ab757
3 changed files with 40 additions and 8 deletions

View File

@ -11,7 +11,6 @@ import org.bukkit.World.Environment;
import org.bukkit.WorldBorder; import org.bukkit.WorldBorder;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -23,6 +22,11 @@ public class UtilWorld
return Bukkit.getServer().getWorld(world); return Bukkit.getServer().getWorld(world);
} }
public static boolean isInChunk(Location location, Chunk chunk)
{
return location.getChunk().getX() == chunk.getX() && location.getChunk().getZ() == chunk.getZ() && chunk.getWorld().equals(location.getChunk().getWorld());
}
public static boolean areChunksEqual(Location first, Location second) public static boolean areChunksEqual(Location first, Location second)
{ {
return first.getBlockX() >> 4 == second.getBlockX() >> 4 && first.getBlockZ() >> 4 == second.getBlockZ() >> 4; return first.getBlockX() >> 4 == second.getBlockX() >> 4 && first.getBlockZ() >> 4 == second.getBlockZ() >> 4;

View File

@ -792,10 +792,12 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{ {
player.setOp(true); player.setOp(true);
} }
if(player.getInventory().getHelmet() != null) { //Reset helmet to fix 1 damage bug if (player.getInventory().getHelmet() != null) //Reset helmet to fix 1 damage bug
{
ItemStack helmet = player.getInventory().getHelmet().clone(); ItemStack helmet = player.getInventory().getHelmet().clone();
player.getInventory().setHelmet(null); player.getInventory().setHelmet(null);
runSyncLater(() -> { runSyncLater(() ->
{
player.getInventory().setHelmet(helmet); player.getInventory().setHelmet(helmet);
}, 20L); }, 20L);
} }
@ -806,7 +808,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{ {
// happens 20 ticks later because player channels don't // happens 20 ticks later because player channels don't
// seem to work immediately after joining. // seem to work immediately after joining.
runSyncLater(() -> { runSyncLater(() ->
{
ByteArrayDataOutput bado = ByteStreams.newDataOutput(); ByteArrayDataOutput bado = ByteStreams.newDataOutput();
bado.writeUTF("no_xray"); bado.writeUTF("no_xray");
@ -844,7 +847,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
for (String message : messages) for (String message : messages)
{ {
if (!event.getMessage().equalsIgnoreCase("/" + message) && !event.getMessage().startsWith("/" + message + " ")) if (!event.getMessage().equalsIgnoreCase("/" + message) && !event.getMessage().toLowerCase().startsWith("/" + message + " "))
{ {
continue; continue;
} }
@ -903,7 +906,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
for (Player other : event.getRecipients()) for (Player other : event.getRecipients())
{ {
if (_tutorial.inTutorial(other)) if (_tutorial.inTutorial(other))
{
continue; continue;
}
UtilPlayer.message(other, String.format(rank + C.cYellow + "%s " + C.cWhite + "%s", event.getPlayer().getName(), event.getMessage())); UtilPlayer.message(other, String.format(rank + C.cYellow + "%s " + C.cWhite + "%s", event.getPlayer().getName(), event.getMessage()));
} }
@ -917,7 +922,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
for (Player other : event.getRecipients()) for (Player other : event.getRecipients())
{ {
if (_tutorial.inTutorial(other)) if (_tutorial.inTutorial(other))
{
continue; continue;
}
ClanInfo otherClan = _clanUtility.getClanByPlayer(other); ClanInfo otherClan = _clanUtility.getClanByPlayer(other);
@ -940,7 +947,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void disableObsidian(BlockBreakEvent event) public void disableObsidian(BlockBreakEvent event)
{ {
if(event.getBlock().getType().equals(Material.OBSIDIAN)) if (event.getBlock().getType().equals(Material.OBSIDIAN))
{ {
event.setCancelled(true); event.setCancelled(true);
event.getBlock().setType(Material.AIR); event.getBlock().setType(Material.AIR);
@ -976,7 +983,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
String rank = _clientManager.Get(event.getPlayer()).GetRank().getTag(true, true) + " "; String rank = _clientManager.Get(event.getPlayer()).GetRank().getTag(true, true) + " ";
if (!_clientManager.Get(event.getPlayer()).GetRank().has(Rank.TWITCH)) if (!_clientManager.Get(event.getPlayer()).GetRank().has(Rank.TWITCH))
{
rank = ""; rank = "";
}
if (client.isClanChat() && clan != null) if (client.isClanChat() && clan != null)
{ {
@ -1028,7 +1037,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
String rank = _clientManager.Get(caller).GetRank().getTag(true, true) + " "; String rank = _clientManager.Get(caller).GetRank().getTag(true, true) + " ";
if (!_clientManager.Get(caller).GetRank().has(Rank.TWITCH)) if (!_clientManager.Get(caller).GetRank().has(Rank.TWITCH))
{
rank = ""; rank = "";
}
handleClanChat(caller, message, clan, rank); handleClanChat(caller, message, clan, rank);
} }
@ -1038,7 +1049,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
String rank = _clientManager.Get(caller).GetRank().getTag(true, true) + " "; String rank = _clientManager.Get(caller).GetRank().getTag(true, true) + " ";
if (!_clientManager.Get(caller).GetRank().has(Rank.TWITCH)) if (!_clientManager.Get(caller).GetRank().has(Rank.TWITCH))
{
rank = ""; rank = "";
}
handleAllyChat(caller, message, clan, rank); handleAllyChat(caller, message, clan, rank);
} }
@ -1316,7 +1329,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
public void updateBedStatus(UpdateEvent event) public void updateBedStatus(UpdateEvent event)
{ {
if (event.getType() != UpdateType.TWOSEC) if (event.getType() != UpdateType.TWOSEC)
{
return; return;
}
for (String name : getClanNameSet()) for (String name : getClanNameSet())
{ {
@ -1391,7 +1406,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{ {
_clanMemberLeftMap.remove(uuid); _clanMemberLeftMap.remove(uuid);
_warPointEvasion.resetCooldown(uuid); _warPointEvasion.resetCooldown(uuid);
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
@ -1405,7 +1419,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{ {
if (event.getEntered() instanceof Player && event.getVehicle() instanceof Horse) if (event.getEntered() instanceof Player && event.getVehicle() instanceof Horse)
{ {
if(!Recharge.Instance.use((Player) event.getEntered(), "Ride Horse", 2 * 20L, true, false)) if (!Recharge.Instance.use((Player) event.getEntered(), "Ride Horse", 2 * 20L, true, false))
{ {
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -20,6 +20,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.inventory.HorseInventory; import org.bukkit.inventory.HorseInventory;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -34,6 +35,7 @@ import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
@ -482,6 +484,18 @@ public class MountManager extends MiniDbClientPlugin<MountOwnerData>
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event)
{
_spawnedMounts.entrySet().forEach(entry ->
{
if (UtilWorld.isInChunk(entry.getKey().getLocation(), event.getChunk()))
{
entry.getValue().despawn(false);
}
});
}
@Override @Override
public String getQuery(int accountId, String uuid, String name) public String getQuery(int accountId, String uuid, String name)
{ {