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

View file

@ -37,9 +37,9 @@ public class Players {
return p;
} else {
LCPlayer p = players.get(player.getName());
/*if (player != p.getPlayer())
p.updatePlayer(player);*/
p.touch();
if (player != p.getPlayer())
p.updatePlayer(player);
//p.touch();
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.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Players;
@ -60,6 +61,10 @@ public class MainListener implements Listener {
if (!Players.get(event.getPlayer()).onSetGameMode(event.getNewGameMode()))
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".

View file

@ -21,7 +21,7 @@ import de.jaschastarke.minecraft.limitedcreative.Players;
import de.jaschastarke.minecraft.utils.Util;
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
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.PlayerUpdateAreaEvent;
@ -92,7 +92,7 @@ public class RegionListener implements Listener {
}
@EventHandler
public void onPlayerChangedArea(PlayerChangedAreaEvent event) {
public void onPlayerChangedArea(PlayerNewLocationAreaEvent 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.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
import de.jaschastarke.minecraft.worldguard.events.PlayerNewLocationAreaEvent;
import de.jaschastarke.minecraft.worldguard.events.PlayerSetAreaEvent;
public class CListener implements Listener {
@ -65,6 +67,14 @@ public class CListener implements Listener {
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
public void onPlayerLogin(PlayerJoinEvent event) {
String new_hash = com.getRegionManager().getRegionsHash(event.getPlayer().getLocation());

View file

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