(still in) v0.9.5-beta:

- Optimized Player Respawn
This commit is contained in:
Jascha Starke 2012-02-25 18:27:30 +01:00
parent bd22b29b21
commit 64b2beac27
7 changed files with 113 additions and 48 deletions

View file

@ -51,32 +51,32 @@ import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
public class LCPlayer { public class LCPlayer {
private static Core plugin = Core.plugin; private static Core plugin = Core.plugin;
//private Player player; private Player player;
private String name; //private String name;
private Inventory _inv; private Inventory _inv;
private GameMode _permanent_gamemode = null; private GameMode _permanent_gamemode = null;
private long _timestamp; //private long _timestamp;
public LCPlayer(Player player) { public LCPlayer(Player player) {
//this.player = player; this.player = player;
name = player.getName(); //name = player.getName();
touch(); //touch();
if (!this.isRegionGameMode(player.getGameMode())) { if (!this.isRegionGameMode(player.getGameMode())) {
setPermanentGameMode(player.getGameMode()); setPermanentGameMode(player.getGameMode());
} }
} }
/*private void updatePlayer(Player player) {
public void updatePlayer(Player player) {
this.player = player; this.player = player;
_inv = null; }
}*/
public Player getPlayer() { public Player getPlayer() {
//return player; return player;
return plugin.getServer().getPlayerExact(name); //return plugin.getServer().getPlayerExact(name); (doesn't work will revive)
} }
public String getName() { public String getName() {
return name; return player.getName();
} }
public Inventory getInv() { public Inventory getInv() {
@ -85,13 +85,13 @@ public class LCPlayer {
return _inv; return _inv;
} }
public void touch() { /*public void touch() {
_timestamp = System.currentTimeMillis(); _timestamp = System.currentTimeMillis();
} }
public boolean isOutdated() { public boolean isOutdated() {
return (getPlayer() == null || !getPlayer().isOnline()) && return (getPlayer() == null || !getPlayer().isOnline()) &&
_timestamp < (System.currentTimeMillis() - Players.CLEANUP_TIMEOUT); _timestamp < (System.currentTimeMillis() - Players.CLEANUP_TIMEOUT);
} }*/
private Map<String, Object> options = new HashMap<String, Object>(); private Map<String, Object> options = new HashMap<String, Object>();
public void setRegionGameMode(final GameMode gm) { public void setRegionGameMode(final GameMode gm) {
@ -209,6 +209,12 @@ public class LCPlayer {
return true; return true;
} }
public void onRevive() {
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
setCreativeArmor();
}
}
public void setCreativeArmor() { public void setCreativeArmor() {
Map<String, MaterialData> armor = plugin.config.getCreativeArmor(); Map<String, MaterialData> armor = plugin.config.getCreativeArmor();
if (armor != null) { if (armor != null) {

View file

@ -37,9 +37,9 @@ public class Players {
return p; return p;
} else { } else {
LCPlayer p = players.get(player.getName()); LCPlayer p = players.get(player.getName());
/*if (player != p.getPlayer()) if (player != p.getPlayer())
p.updatePlayer(player);*/ p.updatePlayer(player);
p.touch(); //p.touch();
return p; return p;
} }
} }

View file

@ -25,6 +25,7 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import de.jaschastarke.minecraft.limitedcreative.Core; import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Players; import de.jaschastarke.minecraft.limitedcreative.Players;
@ -60,6 +61,10 @@ public class MainListener implements Listener {
if (!Players.get(event.getPlayer()).onSetGameMode(event.getNewGameMode())) if (!Players.get(event.getPlayer()).onSetGameMode(event.getNewGameMode()))
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
Players.get(event.getPlayer()).onRevive();
}
/** /**
* Also needed if WorldGuard-Feature is enabled, so can not moved to optional Listener "Limit". * Also needed if WorldGuard-Feature is enabled, so can not moved to optional Listener "Limit".

View file

@ -21,7 +21,7 @@ import de.jaschastarke.minecraft.limitedcreative.Players;
import de.jaschastarke.minecraft.utils.Util; import de.jaschastarke.minecraft.utils.Util;
import de.jaschastarke.minecraft.worldguard.ApplicableRegions; import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
import de.jaschastarke.minecraft.worldguard.CRegionManager; import de.jaschastarke.minecraft.worldguard.CRegionManager;
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent; import de.jaschastarke.minecraft.worldguard.events.PlayerNewLocationAreaEvent;
import de.jaschastarke.minecraft.worldguard.events.PlayerSetAreaEvent; import de.jaschastarke.minecraft.worldguard.events.PlayerSetAreaEvent;
import de.jaschastarke.minecraft.worldguard.events.PlayerUpdateAreaEvent; import de.jaschastarke.minecraft.worldguard.events.PlayerUpdateAreaEvent;
@ -92,7 +92,7 @@ public class RegionListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerChangedArea(PlayerChangedAreaEvent event) { public void onPlayerChangedArea(PlayerNewLocationAreaEvent event) {
Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getRegionSet().allows(Flags.CREATIVE, event.getPlayer()), event); Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getRegionSet().allows(Flags.CREATIVE, event.getPlayer()), event);
} }

View file

@ -25,9 +25,11 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent; import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
import de.jaschastarke.minecraft.worldguard.events.PlayerNewLocationAreaEvent;
import de.jaschastarke.minecraft.worldguard.events.PlayerSetAreaEvent; import de.jaschastarke.minecraft.worldguard.events.PlayerSetAreaEvent;
public class CListener implements Listener { public class CListener implements Listener {
@ -65,6 +67,14 @@ public class CListener implements Listener {
onPlayerMove(event); onPlayerMove(event);
} }
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
String new_hash = com.getRegionManager().getRegionsHash(event.getRespawnLocation());
PlayerNewLocationAreaEvent areaevent = new PlayerNewLocationAreaEvent(event.getPlayer(), event.getRespawnLocation(), new_hash);
Bukkit.getServer().getPluginManager().callEvent(areaevent);
CPlayer.get(event.getPlayer()).setHash(new_hash);
}
@EventHandler @EventHandler
public void onPlayerLogin(PlayerJoinEvent event) { public void onPlayerLogin(PlayerJoinEvent event) {
String new_hash = com.getRegionManager().getRegionsHash(event.getPlayer().getLocation()); String new_hash = com.getRegionManager().getRegionsHash(event.getPlayer().getLocation());

View file

@ -17,9 +17,7 @@
*/ */
package de.jaschastarke.minecraft.worldguard.events; package de.jaschastarke.minecraft.worldguard.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
@ -27,34 +25,19 @@ import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
import de.jaschastarke.minecraft.worldguard.Interface; import de.jaschastarke.minecraft.worldguard.Interface;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class PlayerChangedAreaEvent extends PlayerAreaEvent implements Cancellable { public class PlayerChangedAreaEvent extends PlayerNewLocationAreaEvent implements Cancellable {
private PlayerMoveEvent event; private PlayerMoveEvent event;
private String _previous_hash; private String _previous_hash;
private String _hash;
private boolean _cancelled = false; private boolean _cancelled = false;
public PlayerChangedAreaEvent(PlayerMoveEvent moveevent) { public PlayerChangedAreaEvent(PlayerMoveEvent moveevent) {
super(moveevent.getPlayer(), moveevent.getTo());
event = moveevent; event = moveevent;
} }
public PlayerChangedAreaEvent(PlayerMoveEvent moveevent, String previous_hash, String new_hash) { public PlayerChangedAreaEvent(PlayerMoveEvent moveevent, String previous_hash, String new_hash) {
super(moveevent.getPlayer(), moveevent.getTo(), new_hash);
event = moveevent; event = moveevent;
_previous_hash = previous_hash; _previous_hash = previous_hash;
_hash = new_hash;
}
@Override
public String getRegionHash() {
if (_hash == null)
_hash = Interface.getInstance().getRegionManager().getRegionsHash(event.getTo());
return _hash;
}
@Override
public ApplicableRegions getRegionSet() {
return Interface.getInstance().getRegionManager().getRegionSet(event.getTo());
}
public Player getPlayer() {
return event.getPlayer();
} }
public boolean isTeleport() { public boolean isTeleport() {
@ -79,15 +62,6 @@ public class PlayerChangedAreaEvent extends PlayerAreaEvent implements Cancellab
return getClass().getSimpleName()+"["+getPreviousRegionHash()+" -> "+getRegionHash()+"]"; return getClass().getSimpleName()+"["+getPreviousRegionHash()+" -> "+getRegionHash()+"]";
} }
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return _cancelled; return _cancelled;

View file

@ -0,0 +1,70 @@
/*
* Limited Creative - (Bukkit Plugin)
* Copyright (C) 2012 jascha@ja-s.de
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.jaschastarke.minecraft.worldguard.events;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
import de.jaschastarke.minecraft.worldguard.Interface;
@SuppressWarnings("serial")
public class PlayerNewLocationAreaEvent extends PlayerAreaEvent {
private Location location;
private Player player;
private String _hash;
public PlayerNewLocationAreaEvent(Player player, Location new_location) {
this.player = player;
location = new_location;
}
public PlayerNewLocationAreaEvent(Player player, Location new_location, String new_hash) {
this(player, new_location);
_hash = new_hash;
}
@Override
public String getRegionHash() {
if (_hash == null)
_hash = Interface.getInstance().getRegionManager().getRegionsHash(location);
return _hash;
}
@Override
public ApplicableRegions getRegionSet() {
return Interface.getInstance().getRegionManager().getRegionSet(location);
}
public Player getPlayer() {
return player;
}
public String toString() {
return getClass().getSimpleName()+"["+getRegionHash()+"]";
}
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}