Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix players being allowed to teleport into arenas after leaving them. #314

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 40 additions & 40 deletions src/main/java/com/garbagemule/MobArena/ArenaListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,20 @@ public ArenaListener(Arena arena, MobArena plugin) {
this.canShare = s.getBoolean("share-items-in-arena", true);
this.autoIgniteTNT = s.getBoolean("auto-ignite-tnt", false);
this.useClassChests = s.getBoolean("use-class-chests", false);

this.classLimits = arena.getClassLimitManager();

this.allowMonsters = arena.getWorld().getAllowMonsters();

this.banned = new HashSet<Player>();
}

void pvpActivate() {
if (arena.isRunning() && !arena.getPlayersInArena().isEmpty()) {
pvpEnabled = pvpOn;
}
}

void pvpDeactivate() {
if (pvpOn) pvpEnabled = false;
}
Expand All @@ -138,17 +138,17 @@ public void onBlockBreak(BlockBreakEvent event) {

// If the arena isn't protected, care
if (!protect) return;

if (!arena.getRegion().contains(event.getBlock().getLocation()))
return;

if (!arena.inArena(event.getPlayer())) {
if (arena.inEditMode())
return;
else
event.setCancelled(true);
}

if (onBlockDestroy(event))
return;

Expand Down Expand Up @@ -182,21 +182,21 @@ public void onBlockBurn(BlockBurnEvent event) {
private boolean onBlockDestroy(BlockEvent event) {
if (arena.inEditMode())
return true;

if (!arena.isRunning())
return false;

Block b = event.getBlock();
if (arena.removeBlock(b) || b.getType() == Material.TNT)
return true;

if (softRestore) {
if (arena.isProtected())
return false;

BlockState state = b.getState();
Repairable r = null;

if (state instanceof InventoryHolder)
r = new RepairableContainer(state);
else if (state instanceof Sign)
Expand All @@ -207,7 +207,7 @@ else if (state.getData() instanceof Attachable)
r = new RepairableBlock(state);

arena.addRepairable(r);

if (!softRestoreDrops)
b.setTypeId(0);
return true;
Expand Down Expand Up @@ -259,11 +259,11 @@ public void onBlockPlace(BlockPlaceEvent event) {
arena.addBlock(b.getRelative(0, 1, 0));
}
}

private void setPlanter(Metadatable tnt, Player planter) {
tnt.setMetadata("mobarena-planter", new FixedMetadataValue(plugin, planter));
}

private Player getPlanter(Metadatable tnt) {
List<MetadataValue> values = tnt.getMetadata("mobarena-planter");
for (MetadataValue value : values) {
Expand Down Expand Up @@ -474,9 +474,9 @@ else if (softRestore)
}

/******************************************************
*
*
* DEATH LISTENERS
*
*
******************************************************/

public void onEntityDeath(EntityDeathEvent event) {
Expand Down Expand Up @@ -528,11 +528,11 @@ public boolean onPlayerRespawn(PlayerRespawnEvent event) {
arena.playerRespawn(p);
return true;
}

private void onMountDeath(EntityDeathEvent event) {
// Shouldn't ever happen
}

private void onMonsterDeath(EntityDeathEvent event) {
EntityDamageEvent e1 = event.getEntity().getLastDamageCause();
EntityDamageByEntityEvent e2 = (e1 instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) e1 : null;
Expand Down Expand Up @@ -612,9 +612,9 @@ private ItemStack getRandomItem(List<ItemStack> stacks) {
}

/******************************************************
*
*
* DAMAGE LISTENERS
*
*
******************************************************/

public void onEntityDamage(EntityDamageEvent event) {
Expand Down Expand Up @@ -698,7 +698,7 @@ private void onPetDamage(EntityDamageEvent event, Wolf pet, Entity damager) {
private void onMountDamage(EntityDamageEvent event, Horse mount, Entity damager) {
event.setCancelled(true);
}

private void onMonsterDamage(EntityDamageEvent event, Entity monster, Entity damager) {
if (damager instanceof Player) {
Player p = (Player) damager;
Expand All @@ -723,15 +723,15 @@ else if (damager instanceof LivingEntity) {
event.setCancelled(true);
}
}

private void onGolemDamage(EntityDamageEvent event, Entity golem, Entity damager) {
if (damager instanceof Player) {
Player p = (Player) damager;
if (!arena.inArena(p)) {
event.setCancelled(true);
return;
}

if (!pvpEnabled) {
event.setCancelled(true);
}
Expand Down Expand Up @@ -819,13 +819,13 @@ else if (event.getTarget() instanceof Player && !arena.inArena((Player) event.ge
}
}
}

public void onEntityTeleport(EntityTeleportEvent event) {
if (region.contains(event.getFrom()) || region.contains(event.getTo())) {
event.setCancelled(true);
}
}

public void onPotionSplash(PotionSplashEvent event) {
ThrownPotion potion = event.getPotion();
if (!region.contains(potion.getLocation())) {
Expand Down Expand Up @@ -910,18 +910,18 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
event.setCancelled(true);
}
}

// If the player is in the lobby, just cancel
else if (arena.inLobby(p)) {
Messenger.tell(p, Msg.LOBBY_DROP_ITEM);
event.setCancelled(true);
}

// Same if it's a spectator, but...
else if (arena.inSpec(p)) {
Messenger.tell(p, Msg.LOBBY_DROP_ITEM);
event.setCancelled(true);

// If the spectator isn't in the region, force them to leave
if (!region.contains(p.getLocation())) {
Messenger.tell(p, Msg.MISC_MA_LEAVE_REMINDER);
Expand Down Expand Up @@ -1012,15 +1012,15 @@ private void handleSign(Sign sign, Player p) {
Messenger.tell(p, Msg.LOBBY_CLASS_PERMISSION);
return;
}

ArenaClass oldAC = arena.getArenaPlayer(p).getArenaClass();
ArenaClass newAC = arena.getClasses().get(className);

// Same class, do nothing.
if (newAC.equals(oldAC)) {
return;
}

// If the new class is full, inform the player.
if (!classLimits.canPlayerJoinClass(newAC)) {
Messenger.tell(p, Msg.LOBBY_CLASS_FULL);
Expand All @@ -1035,7 +1035,7 @@ private void handleSign(Sign sign, Player p) {
return;
}
}

// Otherwise, leave the old class, and pick the new!
classLimits.playerLeftClass(oldAC, p);
classLimits.playerPickedClass(newAC, p);
Expand Down Expand Up @@ -1091,7 +1091,7 @@ public void run() {
// Then, if no chest was found, check the pillar behind the sign
if (blockChest == null) blockChest = findChestBelow(blockBehind, 6);
}

// If a chest was found, get the contents
if (blockChest != null) {
InventoryHolder holder = (InventoryHolder) blockChest.getState();
Expand Down Expand Up @@ -1125,10 +1125,10 @@ public void run() {
}
});
}

private Block findChestBelow(Block b, int left) {
if (left < 0) return null;

if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
return b;
}
Expand Down Expand Up @@ -1164,7 +1164,7 @@ public void run() {
}
}, ticks);
}

public TeleportResponse onPlayerTeleport(PlayerTeleportEvent event) {
if (!arena.isEnabled() || !region.isSetup() || arena.inEditMode() || allowTeleport) {
return TeleportResponse.IDGAF;
Expand All @@ -1179,7 +1179,7 @@ public TeleportResponse onPlayerTeleport(PlayerTeleportEvent event) {
if (p.hasPermission("mobarena.admin.teleport")) {
return TeleportResponse.ALLOW;
}

// Players not in the arena are free to warp out.
if (!arena.inArena(p) && !arena.inLobby(p) && !arena.inSpec(p)) {
return TeleportResponse.ALLOW;
Expand All @@ -1198,8 +1198,8 @@ else if (region.contains(to)) {
if (p.hasPermission("mobarena.admin.teleport")) {
return TeleportResponse.ALLOW;
}
if (region.isWarp(from) || region.isWarp(to) || to.equals(arena.getPlayerEntry(p))) {

if ((arena.getAllPlayers().contains(event.getPlayer()) && (region.isWarp(from) || region.isWarp(to))) || to.equals(arena.getPlayerEntry(p))) {
Copy link
Collaborator

@slipcor slipcor Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you saw my preview comment, ignore it please. I found that this actually does fix the issue! I will talk to the mule tomorrow to include this line. Thanks for your input!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

return TeleportResponse.ALLOW;
}

Expand Down Expand Up @@ -1242,10 +1242,10 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
public void onPlayerPreLogin(PlayerLoginEvent event) {
Player p = event.getPlayer();
if (p == null || !p.isOnline()) return;

Arena arena = plugin.getArenaMaster().getArenaWithPlayer(p);
if (arena == null) return;

arena.playerLeave(p);
}

Expand Down