mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-09 12:20:30 +01:00
Finished player handling rewrite. Resolves #63
This commit is contained in:
parent
1b6ed7432a
commit
6dd6133978
4
pom.xml
4
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.github.dre2n</groupId>
|
||||
<artifactId>dungeonsxl</artifactId>
|
||||
<version>0.11.4</version>
|
||||
<version>0.12-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>DungeonsXL</name>
|
||||
<url>https://dre2n.github.io</url>
|
||||
@ -55,7 +55,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.9.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.9.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -20,6 +20,7 @@ import io.github.dre2n.commons.command.BRCommand;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
@ -95,7 +96,7 @@ public class CreateCommand extends BRCommand {
|
||||
MessageUtil.log(plugin, DMessages.LOG_WORLD_GENERATION_FINISHED.getMessage());
|
||||
|
||||
// Tp Player
|
||||
new DGamePlayer(player, editWorld.getWorld(), true);
|
||||
new DEditPlayer(player, editWorld.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import io.github.dre2n.commons.command.BRCommand;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
@ -71,7 +72,7 @@ public class EditCommand extends BRCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
new DGamePlayer(player, editWorld.getWorld(), true);
|
||||
new DEditPlayer(player, editWorld.getWorld());
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ package io.github.dre2n.dungeonsxl.command;
|
||||
|
||||
import io.github.dre2n.commons.command.BRCommand;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
@ -32,8 +32,6 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class EscapeCommand extends BRCommand {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
public EscapeCommand() {
|
||||
setCommand("escape");
|
||||
setMinArgs(0);
|
||||
@ -46,14 +44,12 @@ public class EscapeCommand extends BRCommand {
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
if (dPlayer != null) {
|
||||
DEditPlayer dPlayer = DEditPlayer.getByPlayer(player);
|
||||
|
||||
if (!dPlayer.isEditing()) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
return;
|
||||
}
|
||||
if (DGamePlayer.getByPlayer(player) != null) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
|
||||
} else if (dPlayer != null) {
|
||||
dPlayer.escape();
|
||||
|
||||
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.event.dplayer;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@ -35,7 +35,7 @@ public class DPlayerUpdateEvent extends DPlayerEvent implements Cancellable {
|
||||
private boolean kick;
|
||||
private boolean triggerAllInDistance;
|
||||
|
||||
public DPlayerUpdateEvent(DGamePlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) {
|
||||
public DPlayerUpdateEvent(DInstancePlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) {
|
||||
super(dPlayer);
|
||||
this.locationValid = locationValid;
|
||||
this.teleportWolf = teleportWolf;
|
||||
|
@ -28,9 +28,11 @@ import io.github.dre2n.dungeonsxl.global.GameSign;
|
||||
import io.github.dre2n.dungeonsxl.global.GlobalProtection;
|
||||
import io.github.dre2n.dungeonsxl.global.GroupSign;
|
||||
import io.github.dre2n.dungeonsxl.global.LeaveSign;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayers;
|
||||
import io.github.dre2n.dungeonsxl.player.DSavePlayer;
|
||||
@ -216,7 +218,7 @@ public class PlayerListener implements Listener {
|
||||
if (EditWorld.getByWorld(player.getWorld()) != null) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (item.getType() == Material.STICK) {
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DEditPlayer dPlayer = DEditPlayer.getByPlayer(player);
|
||||
if (dPlayer != null) {
|
||||
dPlayer.poke(clickedBlock);
|
||||
event.setCancelled(true);
|
||||
@ -315,15 +317,21 @@ public class PlayerListener implements Listener {
|
||||
public void onDropItem(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dPlayer.isEditing() && !plugin.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) {
|
||||
if (dPlayer instanceof DEditPlayer && !plugin.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (!(dPlayer instanceof DGamePlayer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DGamePlayer gamePlayer = (DGamePlayer) dPlayer;
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
if (dGroup == null) {
|
||||
return;
|
||||
@ -334,12 +342,12 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dPlayer.isReady()) {
|
||||
if (!gamePlayer.isReady()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
|
||||
GameWorld gameWorld = GameWorld.getByWorld(gamePlayer.getWorld());
|
||||
|
||||
for (Material material : gameWorld.getConfig().getSecureObjects()) {
|
||||
if (material == event.getItemDrop().getItemStack().getType()) {
|
||||
@ -355,13 +363,13 @@ public class PlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
plugin.getDPlayers().getByPlayer(player).applyRespawnInventory();
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dPlayer.isEditing()) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
|
||||
if (dPlayer instanceof DEditPlayer) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(((DEditPlayer) dPlayer).getWorld());
|
||||
if (editWorld == null) {
|
||||
return;
|
||||
}
|
||||
@ -373,8 +381,10 @@ public class PlayerListener implements Listener {
|
||||
event.setRespawnLocation(editWorld.getLobbyLocation());
|
||||
}
|
||||
|
||||
} else {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
|
||||
} else if (dPlayer instanceof DGamePlayer) {
|
||||
DGamePlayer gamePlayer = (DGamePlayer) dPlayer;
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(gamePlayer.getWorld());
|
||||
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
@ -382,7 +392,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
|
||||
|
||||
Location respawn = dPlayer.getCheckpoint();
|
||||
Location respawn = gamePlayer.getCheckpoint();
|
||||
|
||||
if (respawn == null) {
|
||||
respawn = dGroup.getGameWorld().getStartLocation();
|
||||
@ -400,8 +410,8 @@ public class PlayerListener implements Listener {
|
||||
new RespawnTask(player, respawn).runTaskLater(plugin, 10);
|
||||
|
||||
// Don't forget Doge!
|
||||
if (dPlayer.getWolf() != null) {
|
||||
dPlayer.getWolf().teleport(respawn);
|
||||
if (gamePlayer.getWolf() != null) {
|
||||
gamePlayer.getWolf().teleport(respawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -448,7 +458,10 @@ public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
if (!(dPlayers.getByPlayer(player) instanceof DInstancePlayer)) {
|
||||
return;
|
||||
}
|
||||
DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(player);
|
||||
|
||||
if (dPlayer == null) {
|
||||
dPlayers.removePlayer(dPlayer);
|
||||
@ -467,13 +480,13 @@ public class PlayerListener implements Listener {
|
||||
|
||||
} else if (timeUntilKickOfflinePlayer > 0) {
|
||||
dGroup.sendMessage(DMessages.PLAYER_OFFLINE.getMessage(dPlayer.getPlayer().getName(), String.valueOf(timeUntilKickOfflinePlayer)), player);
|
||||
dPlayer.setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
|
||||
((DGamePlayer) dPlayer).setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
|
||||
|
||||
} else {
|
||||
dGroup.sendMessage(DMessages.PLAYER_OFFLINE_NEVER.getMessage(dPlayer.getPlayer().getName()), player);
|
||||
}
|
||||
|
||||
} else if (dPlayer.isEditing()) {
|
||||
} else if (dPlayer instanceof DEditPlayer) {
|
||||
dPlayer.leave();
|
||||
}
|
||||
}
|
||||
@ -566,17 +579,17 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(event.getPlayer());
|
||||
if (dPlayer == null) {
|
||||
if (!(dPlayers.getByPlayer(event.getPlayer()) instanceof DInstancePlayer)) {
|
||||
return;
|
||||
}
|
||||
DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(event.getPlayer());
|
||||
|
||||
String command = event.getMessage().toLowerCase();
|
||||
ArrayList<String> commandWhitelist = new ArrayList<>();
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
|
||||
|
||||
if (dPlayer.isEditing()) {
|
||||
if (dPlayer instanceof DEditPlayer) {
|
||||
if (DPermissions.hasPermission(event.getPlayer(), DPermissions.CMD_EDIT)) {
|
||||
return;
|
||||
|
||||
|
@ -16,15 +16,180 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent;
|
||||
import static io.github.dre2n.dungeonsxl.player.DGlobalPlayer.plugin;
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
/**
|
||||
* Represents a player in an EditWorld.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DEditPlayer extends DGlobalPlayer {
|
||||
public class DEditPlayer extends DInstancePlayer {
|
||||
|
||||
public DEditPlayer(DGlobalPlayer player) {
|
||||
super(player.getPlayer());
|
||||
private String[] linesCopy;
|
||||
|
||||
public DEditPlayer(DGlobalPlayer player, EditWorld world) {
|
||||
this(player.getPlayer(), world.getWorld());
|
||||
}
|
||||
|
||||
public DEditPlayer(Player player, World world) {
|
||||
super(player, world);
|
||||
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
clearPlayerData();
|
||||
|
||||
Location teleport = EditWorld.getByWorld(world).getLobbyLocation();
|
||||
if (teleport == null) {
|
||||
PlayerUtil.secureTeleport(player, world.getSpawnLocation());
|
||||
} else {
|
||||
PlayerUtil.secureTeleport(player, teleport);
|
||||
}
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the linesCopy
|
||||
*/
|
||||
public String[] getLinesCopy() {
|
||||
return linesCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param linesCopy
|
||||
* the linesCopy to set
|
||||
*/
|
||||
public void setLinesCopy(String[] linesCopy) {
|
||||
this.linesCopy = linesCopy;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Escape the EditWorld without saving.
|
||||
*/
|
||||
public void escape() {
|
||||
delete();
|
||||
getSavePlayer().reset(false);
|
||||
}
|
||||
|
||||
public void poke(Block block) {
|
||||
if (block.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
String[] lines = sign.getLines();
|
||||
if (lines[0].isEmpty() && lines[1].isEmpty() && lines[2].isEmpty() && lines[3].isEmpty()) {
|
||||
if (linesCopy != null) {
|
||||
SignChangeEvent event = new SignChangeEvent(block, getPlayer(), linesCopy);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
sign.setLine(0, event.getLine(0));
|
||||
sign.setLine(1, event.getLine(1));
|
||||
sign.setLine(2, event.getLine(2));
|
||||
sign.setLine(3, event.getLine(3));
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
linesCopy = lines;
|
||||
MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_SIGN_COPIED.getMessage());
|
||||
}
|
||||
} else {
|
||||
String info = "" + block.getType();
|
||||
if (block.getData() != 0) {
|
||||
info = info + "," + block.getData();
|
||||
}
|
||||
MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_BLOCK_INFO.getMessage(info));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave() {
|
||||
getSavePlayer().reset(false);
|
||||
|
||||
EditWorld editWorld = EditWorld.getByWorld(getWorld());
|
||||
if (editWorld != null) {
|
||||
editWorld.save();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(getWorld());
|
||||
editWorld.sendMessage(message);
|
||||
|
||||
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) {
|
||||
if (player.isInChatSpyMode()) {
|
||||
if (!editWorld.getWorld().getPlayers().contains(player.getPlayer())) {
|
||||
MessageUtil.sendMessage(player.getPlayer(), ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(boolean updateSecond) {
|
||||
boolean locationValid = true;
|
||||
Location teleportLocation = player.getLocation();
|
||||
boolean teleportWolf = false;
|
||||
boolean respawnInventory = false;
|
||||
boolean offline = false;
|
||||
boolean kick = false;
|
||||
boolean triggerAllInDistance = false;
|
||||
|
||||
EditWorld editWorld = EditWorld.getByWorld(getWorld());
|
||||
|
||||
if (editWorld != null) {
|
||||
if (editWorld.getLobbyLocation() == null) {
|
||||
teleportLocation = editWorld.getWorld().getSpawnLocation();
|
||||
} else {
|
||||
teleportLocation = editWorld.getLobbyLocation();
|
||||
}
|
||||
}
|
||||
|
||||
DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static DEditPlayer getByPlayer(Player player) {
|
||||
for (DEditPlayer dPlayer : plugin.getDPlayers().getDEditPlayers()) {
|
||||
if (dPlayer.getPlayer().equals(player)) {
|
||||
return dPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DEditPlayer getByName(String name) {
|
||||
for (DEditPlayer dPlayer : plugin.getDPlayers().getDEditPlayers()) {
|
||||
if (dPlayer.getPlayer().getName().equalsIgnoreCase(name)) {
|
||||
return dPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CopyOnWriteArrayList<DEditPlayer> getByWorld(World world) {
|
||||
CopyOnWriteArrayList<DEditPlayer> dPlayers = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (DEditPlayer dPlayer : plugin.getDPlayers().getDEditPlayers()) {
|
||||
if (dPlayer.getWorld() == world) {
|
||||
dPlayers.add(dPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
return dPlayers;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,8 +16,6 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import io.github.dre2n.commons.compatibility.CompatibilityHandler;
|
||||
import io.github.dre2n.commons.compatibility.Version;
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
|
||||
@ -37,7 +35,6 @@ import io.github.dre2n.dungeonsxl.mob.DMob;
|
||||
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
|
||||
import io.github.dre2n.dungeonsxl.reward.Reward;
|
||||
import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger;
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -47,15 +44,12 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
@ -65,15 +59,9 @@ import org.bukkit.potion.PotionEffect;
|
||||
*
|
||||
* @author Frank Baumann, Tobias Schmitz, Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class DGamePlayer extends DGlobalPlayer {
|
||||
public class DGamePlayer extends DInstancePlayer {
|
||||
|
||||
// Variables
|
||||
private World world;
|
||||
|
||||
private DSavePlayer savePlayer;
|
||||
|
||||
private boolean editing;
|
||||
private boolean inDungeonChat = false;
|
||||
private boolean ready = false;
|
||||
private boolean finished = false;
|
||||
|
||||
@ -82,7 +70,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
private Wolf wolf;
|
||||
private int wolfRespawnTime = 30;
|
||||
private long offlineTime;
|
||||
private String[] linesCopy;
|
||||
|
||||
private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, DMessages.PLAYER_TREASURES.getMessage());
|
||||
|
||||
@ -90,65 +77,34 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
private int lives;
|
||||
|
||||
public DGamePlayer(Player player, GameWorld gameWorld) {
|
||||
this(player, gameWorld.getWorld(), false);
|
||||
this(player, gameWorld.getWorld());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DGamePlayer(Player player, World world, boolean editing) {
|
||||
super(player);
|
||||
public DGamePlayer(Player player, World world) {
|
||||
super(player, world);
|
||||
|
||||
this.world = world;
|
||||
WorldConfig worldConfig = GameWorld.getByWorld(world).getConfig();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
if (!Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), null, player.getLevel(),
|
||||
player.getTotalExperience(), player.getHealth(), player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
|
||||
} else {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getInventory().getItemInOffHand(), player.getLevel(),
|
||||
player.getTotalExperience(), player.getHealth(), player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
}
|
||||
this.editing = editing;
|
||||
|
||||
Location teleport;
|
||||
if (this.editing) {
|
||||
this.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||
if (!worldConfig.getKeepInventoryOnEnter()) {
|
||||
clearPlayerData();
|
||||
teleport = EditWorld.getByWorld(world).getLobbyLocation();
|
||||
|
||||
} else {
|
||||
WorldConfig worldConfig = GameWorld.getByWorld(world).getConfig();
|
||||
this.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||
if (!worldConfig.getKeepInventoryOnEnter()) {
|
||||
clearPlayerData();
|
||||
}
|
||||
if (worldConfig.isLobbyDisabled()) {
|
||||
ready();
|
||||
}
|
||||
initialLives = worldConfig.getInitialLives();
|
||||
lives = initialLives;
|
||||
teleport = GameWorld.getByWorld(world).getLobbyLocation();
|
||||
}
|
||||
|
||||
if (worldConfig.isLobbyDisabled()) {
|
||||
ready();
|
||||
}
|
||||
|
||||
initialLives = worldConfig.getInitialLives();
|
||||
lives = initialLives;
|
||||
|
||||
Location teleport = GameWorld.getByWorld(world).getLobbyLocation();
|
||||
if (teleport == null) {
|
||||
PlayerUtil.secureTeleport(player, world.getSpawnLocation());
|
||||
|
||||
} else {
|
||||
PlayerUtil.secureTeleport(player, teleport);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearPlayerData() {
|
||||
getPlayer().getInventory().clear();
|
||||
getPlayer().getInventory().setArmorContents(null);
|
||||
getPlayer().setTotalExperience(0);
|
||||
getPlayer().setLevel(0);
|
||||
getPlayer().setHealth(20);
|
||||
getPlayer().setFoodLevel(20);
|
||||
for (PotionEffect effect : getPlayer().getActivePotionEffects()) {
|
||||
getPlayer().removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @param player
|
||||
@ -158,36 +114,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the world
|
||||
*/
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* the world to set
|
||||
*/
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the savePlayer
|
||||
*/
|
||||
public DSavePlayer getSavePlayer() {
|
||||
return savePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param savePlayer
|
||||
* the savePlayer to set
|
||||
*/
|
||||
public void setSavePlayer(DSavePlayer savePlayer) {
|
||||
this.savePlayer = savePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player is in test mode
|
||||
*/
|
||||
@ -215,31 +141,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isEditing() {
|
||||
return editing;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setEditing(boolean editing) {
|
||||
this.editing = editing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inDungeonChat
|
||||
*/
|
||||
public boolean isInDungeonChat() {
|
||||
return inDungeonChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inDungeonChat
|
||||
* the inDungeonChat to set
|
||||
*/
|
||||
public void setInDungeonChat(boolean inDungeonChat) {
|
||||
this.inDungeonChat = inDungeonChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isReady
|
||||
*/
|
||||
@ -299,7 +200,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
if (dClass.hasDog()) {
|
||||
wolf = (Wolf) world.spawnEntity(getPlayer().getLocation(), EntityType.WOLF);
|
||||
wolf = (Wolf) getWorld().spawnEntity(getPlayer().getLocation(), EntityType.WOLF);
|
||||
wolf.setTamed(true);
|
||||
wolf.setOwner(getPlayer());
|
||||
|
||||
@ -408,21 +309,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
this.offlineTime = offlineTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the linesCopy
|
||||
*/
|
||||
public String[] getLinesCopy() {
|
||||
return linesCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param linesCopy
|
||||
* the linesCopy to set
|
||||
*/
|
||||
public void setLinesCopy(String[] linesCopy) {
|
||||
this.linesCopy = linesCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the treasureInv
|
||||
*/
|
||||
@ -469,116 +355,99 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
public void escape() {
|
||||
delete();
|
||||
savePlayer.reset(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave() {
|
||||
delete();
|
||||
|
||||
if (!editing) {
|
||||
WorldConfig dConfig = GameWorld.getByWorld(world).getConfig();
|
||||
if (finished) {
|
||||
savePlayer.reset(dConfig.getKeepInventoryOnFinish());
|
||||
} else {
|
||||
savePlayer.reset(dConfig.getKeepInventoryOnEscape());
|
||||
}
|
||||
|
||||
WorldConfig dConfig = GameWorld.getByWorld(getWorld()).getConfig();
|
||||
if (finished) {
|
||||
getSavePlayer().reset(dConfig.getKeepInventoryOnFinish());
|
||||
} else {
|
||||
savePlayer.reset(false);
|
||||
getSavePlayer().reset(dConfig.getKeepInventoryOnEscape());
|
||||
}
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||
GameWorld gameWorld = GameWorld.getByWorld(getWorld());
|
||||
DGroup dGroup = DGroup.getByPlayer(getPlayer());
|
||||
|
||||
if (editing) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(world);
|
||||
if (editWorld != null) {
|
||||
editWorld.save();
|
||||
}
|
||||
Game game = Game.getByGameWorld(gameWorld);
|
||||
if (dGroup != null) {
|
||||
dGroup.removePlayer(getPlayer());
|
||||
}
|
||||
|
||||
} else {
|
||||
Game game = Game.getByGameWorld(gameWorld);
|
||||
if (dGroup != null) {
|
||||
dGroup.removePlayer(getPlayer());
|
||||
}
|
||||
// Belohnung
|
||||
if (game != null) {
|
||||
if (finished) {
|
||||
if (game.getType().hasRewards()) {
|
||||
for (Reward reward : gameWorld.getConfig().getRewards()) {
|
||||
reward.giveTo(getPlayer());
|
||||
}
|
||||
|
||||
// Belohnung
|
||||
if (game != null) {
|
||||
if (finished) {
|
||||
if (game.getType().hasRewards()) {
|
||||
for (Reward reward : gameWorld.getConfig().getRewards()) {
|
||||
reward.giveTo(getPlayer());
|
||||
}
|
||||
addTreasure();
|
||||
|
||||
addTreasure();
|
||||
|
||||
// Set Time
|
||||
File file = new File(plugin.getDataFolder() + "/maps/" + gameWorld.getMapName(), "players.yml");
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
playerConfig.set(getPlayer().getUniqueId().toString(), System.currentTimeMillis());
|
||||
// Set Time
|
||||
File file = new File(plugin.getDataFolder() + "/maps/" + gameWorld.getMapName(), "players.yml");
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
playerConfig.save(file);
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
playerConfig.set(getPlayer().getUniqueId().toString(), System.currentTimeMillis());
|
||||
|
||||
try {
|
||||
playerConfig.save(file);
|
||||
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
// Tutorial Permissions
|
||||
if (gameWorld.isTutorial()) {
|
||||
String endGroup = plugin.getMainConfig().getTutorialEndGroup();
|
||||
if (plugin.isGroupEnabled(endGroup)) {
|
||||
plugin.getPermissionProvider().playerAddGroup(getPlayer(), endGroup);
|
||||
}
|
||||
|
||||
// Tutorial Permissions
|
||||
if (gameWorld.isTutorial()) {
|
||||
String endGroup = plugin.getMainConfig().getTutorialEndGroup();
|
||||
if (plugin.isGroupEnabled(endGroup)) {
|
||||
plugin.getPermissionProvider().playerAddGroup(getPlayer(), endGroup);
|
||||
}
|
||||
|
||||
String startGroup = plugin.getMainConfig().getTutorialStartGroup();
|
||||
if (plugin.isGroupEnabled(startGroup)) {
|
||||
plugin.getPermissionProvider().playerRemoveGroup(getPlayer(), startGroup);
|
||||
}
|
||||
String startGroup = plugin.getMainConfig().getTutorialStartGroup();
|
||||
if (plugin.isGroupEnabled(startGroup)) {
|
||||
plugin.getPermissionProvider().playerRemoveGroup(getPlayer(), startGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dGroup != null) {
|
||||
// Give Secure Objects other Players
|
||||
if (!dGroup.isEmpty()) {
|
||||
int i = 0;
|
||||
Player groupPlayer;
|
||||
do {
|
||||
groupPlayer = dGroup.getPlayers().get(i);
|
||||
if (groupPlayer != null) {
|
||||
for (ItemStack itemStack : getPlayer().getInventory()) {
|
||||
if (itemStack != null) {
|
||||
if (gameWorld.getSecureObjects().contains(itemStack.getType())) {
|
||||
groupPlayer.getInventory().addItem(itemStack);
|
||||
}
|
||||
if (dGroup != null) {
|
||||
// Give Secure Objects other Players
|
||||
if (!dGroup.isEmpty()) {
|
||||
int i = 0;
|
||||
Player groupPlayer;
|
||||
do {
|
||||
groupPlayer = dGroup.getPlayers().get(i);
|
||||
if (groupPlayer != null) {
|
||||
for (ItemStack itemStack : getPlayer().getInventory()) {
|
||||
if (itemStack != null) {
|
||||
if (gameWorld.getSecureObjects().contains(itemStack.getType())) {
|
||||
groupPlayer.getInventory().addItem(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
} while (groupPlayer == null);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
} while (groupPlayer == null);
|
||||
}
|
||||
|
||||
if (dGroup.getCaptain().equals(getPlayer()) && dGroup.getPlayers().size() > 0) {
|
||||
// Captain here!
|
||||
Player newCaptain = dGroup.getPlayers().get(0);
|
||||
dGroup.setCaptain(newCaptain);
|
||||
MessageUtil.sendMessage(newCaptain, DMessages.PLAYER_NEW_CAPTAIN.getMessage());
|
||||
// ...*flies away*
|
||||
}
|
||||
if (dGroup.getCaptain().equals(getPlayer()) && dGroup.getPlayers().size() > 0) {
|
||||
// Captain here!
|
||||
Player newCaptain = dGroup.getPlayers().get(0);
|
||||
dGroup.setCaptain(newCaptain);
|
||||
MessageUtil.sendMessage(newCaptain, DMessages.PLAYER_NEW_CAPTAIN.getMessage());
|
||||
// ...*flies away*
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -628,7 +497,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
if (respawn == null) {
|
||||
respawn = world.getSpawnLocation();
|
||||
respawn = getWorld().getSpawnLocation();
|
||||
}
|
||||
|
||||
PlayerUtil.secureTeleport(getPlayer(), respawn);
|
||||
@ -639,7 +508,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
// Respawn Items
|
||||
if (GameWorld.getByWorld(world).getConfig().getKeepInventoryOnDeath()) {
|
||||
if (GameWorld.getByWorld(getWorld()).getConfig().getKeepInventoryOnDeath()) {
|
||||
applyRespawnInventory();
|
||||
}
|
||||
}
|
||||
@ -697,7 +566,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
@ -756,7 +624,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
DPlayerFinishEvent dPlayerFinishEvent = new DPlayerFinishEvent(this, first, hasToWait);
|
||||
plugin.getServer().getPluginManager().callEvent(dPlayerFinishEvent);
|
||||
|
||||
if (dPlayerFinishEvent.isCancelled()) {
|
||||
finished = false;
|
||||
@ -768,7 +635,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dGroup);
|
||||
plugin.getServer().getPluginManager().callEvent(dGroupFinishDungeonEvent);
|
||||
|
||||
if (dGroupFinishDungeonEvent.isCancelled()) {
|
||||
return;
|
||||
@ -790,64 +656,25 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
if (editing) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(world);
|
||||
editWorld.sendMessage(message);
|
||||
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) {
|
||||
if (player.isInChatSpyMode()) {
|
||||
if (!editWorld.getWorld().getPlayers().contains(player.getPlayer())) {
|
||||
MessageUtil.sendMessage(player.getPlayer(), ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
GameWorld gameWorld = GameWorld.getByWorld(getWorld());
|
||||
gameWorld.sendMessage(message);
|
||||
|
||||
} else {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||
gameWorld.sendMessage(message);
|
||||
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) {
|
||||
if (player.isInChatSpyMode()) {
|
||||
if (!gameWorld.getWorld().getPlayers().contains(player.getPlayer())) {
|
||||
MessageUtil.sendMessage(player.getPlayer(), ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message);
|
||||
}
|
||||
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) {
|
||||
if (player.isInChatSpyMode()) {
|
||||
if (!gameWorld.getWorld().getPlayers().contains(player.getPlayer())) {
|
||||
MessageUtil.sendMessage(player.getPlayer(), ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void poke(Block block) {
|
||||
if (block.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
String[] lines = sign.getLines();
|
||||
if (lines[0].isEmpty() && lines[1].isEmpty() && lines[2].isEmpty() && lines[3].isEmpty()) {
|
||||
if (linesCopy != null) {
|
||||
SignChangeEvent event = new SignChangeEvent(block, getPlayer(), linesCopy);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
sign.setLine(0, event.getLine(0));
|
||||
sign.setLine(1, event.getLine(1));
|
||||
sign.setLine(2, event.getLine(2));
|
||||
sign.setLine(3, event.getLine(3));
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
linesCopy = lines;
|
||||
MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_SIGN_COPIED.getMessage());
|
||||
}
|
||||
} else {
|
||||
String info = "" + block.getType();
|
||||
if (block.getData() != 0) {
|
||||
info = info + "," + block.getData();
|
||||
}
|
||||
MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_BLOCK_INFO.getMessage(info));
|
||||
}
|
||||
}
|
||||
|
||||
public void addTreasure() {
|
||||
new DLootInventory(getPlayer(), treasureInv.getContents());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(boolean updateSecond) {
|
||||
boolean locationValid = true;
|
||||
Location teleportLocation = player.getLocation();
|
||||
@ -858,22 +685,12 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
boolean triggerAllInDistance = false;
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(getWorld());
|
||||
EditWorld editWorld = EditWorld.getByWorld(getWorld());
|
||||
|
||||
if (!updateSecond) {
|
||||
if (!getPlayer().getWorld().equals(getWorld())) {
|
||||
locationValid = false;
|
||||
|
||||
if (isEditing()) {
|
||||
if (editWorld != null) {
|
||||
if (editWorld.getLobbyLocation() == null) {
|
||||
teleportLocation = editWorld.getWorld().getSpawnLocation();
|
||||
} else {
|
||||
teleportLocation = editWorld.getLobbyLocation();
|
||||
}
|
||||
}
|
||||
|
||||
} else if (gameWorld != null) {
|
||||
if (gameWorld != null) {
|
||||
DGroup dGroup = DGroup.getByPlayer(getPlayer());
|
||||
|
||||
teleportLocation = getCheckpoint();
|
||||
@ -954,7 +771,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
|
||||
if (kick) {
|
||||
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this, DPlayerKickEvent.Cause.OFFLINE);
|
||||
plugin.getServer().getPluginManager().callEvent(dPlayerKickEvent);
|
||||
|
||||
if (!dPlayerKickEvent.isCancelled()) {
|
||||
leave();
|
||||
@ -966,19 +782,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this DGamePlayer. Creates a DGlobalPlayer to replace it!
|
||||
*/
|
||||
public void delete() {
|
||||
if (player.isOnline()) {
|
||||
// Create a new DGlobalPlayer (outside a dungeon)
|
||||
new DGlobalPlayer(this);
|
||||
|
||||
} else {
|
||||
plugin.getDPlayers().removePlayer(this);
|
||||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static DGamePlayer getByPlayer(Player player) {
|
||||
for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) {
|
||||
@ -1002,7 +805,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
CopyOnWriteArrayList<DGamePlayer> dPlayers = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) {
|
||||
if (dPlayer.world == world) {
|
||||
if (dPlayer.getWorld() == world) {
|
||||
dPlayers.add(dPlayer);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
*
|
||||
* 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 io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import io.github.dre2n.commons.compatibility.CompatibilityHandler;
|
||||
import io.github.dre2n.commons.compatibility.Version;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public abstract class DInstancePlayer extends DGlobalPlayer {
|
||||
|
||||
private DSavePlayer savePlayer;
|
||||
private World world;
|
||||
private boolean inDungeonChat = false;
|
||||
|
||||
public DInstancePlayer(Player player, World world) {
|
||||
super(player);
|
||||
|
||||
double health = player.getHealth();
|
||||
if (!Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), null, player.getLevel(),
|
||||
player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
} else {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getInventory().getItemInOffHand(), player.getLevel(),
|
||||
player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
}
|
||||
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the savePlayer
|
||||
*/
|
||||
public DSavePlayer getSavePlayer() {
|
||||
return savePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param savePlayer
|
||||
* the savePlayer to set
|
||||
*/
|
||||
public void setSavePlayer(DSavePlayer savePlayer) {
|
||||
this.savePlayer = savePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* the instance
|
||||
*/
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* the instance to set
|
||||
*/
|
||||
public void setWorld(World instance) {
|
||||
world = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inDungeonChat
|
||||
*/
|
||||
public boolean isInDungeonChat() {
|
||||
return inDungeonChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inDungeonChat
|
||||
* the inDungeonChat to set
|
||||
*/
|
||||
public void setInDungeonChat(boolean inDungeonChat) {
|
||||
this.inDungeonChat = inDungeonChat;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Clear the player's inventory, potion effects etc.
|
||||
*/
|
||||
public void clearPlayerData() {
|
||||
getPlayer().getInventory().clear();
|
||||
getPlayer().getInventory().setArmorContents(null);
|
||||
getPlayer().setTotalExperience(0);
|
||||
getPlayer().setLevel(0);
|
||||
getPlayer().setHealth(20);
|
||||
getPlayer().setFoodLevel(20);
|
||||
for (PotionEffect effect : getPlayer().getActivePotionEffects()) {
|
||||
getPlayer().removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this DInstancePlayer. Creates a DGlobalPlayer to replace it!
|
||||
*/
|
||||
public void delete() {
|
||||
if (player.isOnline()) {
|
||||
// Create a new DGlobalPlayer (outside a dungeon)
|
||||
new DGlobalPlayer(this);
|
||||
|
||||
} else {
|
||||
plugin.getDPlayers().removePlayer(this);
|
||||
}
|
||||
}
|
||||
|
||||
/* Abstracts */
|
||||
/**
|
||||
* The player leaves the dungeon and / or his group.
|
||||
*/
|
||||
public abstract void leave();
|
||||
|
||||
/**
|
||||
* Sends a message to the player and the world.
|
||||
*/
|
||||
public abstract void sendMessage(String message);
|
||||
|
||||
/**
|
||||
* Repeating checks for the player.
|
||||
*
|
||||
* @param updateSecond
|
||||
* Not all checks have to be done as often as others;
|
||||
* some are just done in "update seconds".
|
||||
*/
|
||||
public abstract void update(boolean updateSecond);
|
||||
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -49,11 +50,24 @@ public class DPlayers {
|
||||
return dGlobalPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGlobalPlayers that are an instance of DInstancePlayer
|
||||
*/
|
||||
public List<DInstancePlayer> getDInstancePlayers() {
|
||||
List<DInstancePlayer> dInstancePlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DInstancePlayer) {
|
||||
dInstancePlayers.add((DInstancePlayer) player);
|
||||
}
|
||||
}
|
||||
return dInstancePlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGlobalPlayers that are an instance of DGamePlayer
|
||||
*/
|
||||
public List<DGamePlayer> getDGamePlayers() {
|
||||
List<DGamePlayer> dPlayers = new CopyOnWriteArrayList<>();
|
||||
List<DGamePlayer> dPlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DGamePlayer) {
|
||||
dPlayers.add((DGamePlayer) player);
|
||||
@ -66,7 +80,7 @@ public class DPlayers {
|
||||
* @return the dGlobalPlayers that are an instance of DEditPlayer
|
||||
*/
|
||||
public List<DEditPlayer> getDEditPlayers() {
|
||||
List<DEditPlayer> dEditPlayers = new CopyOnWriteArrayList<>();
|
||||
List<DEditPlayer> dEditPlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DEditPlayer) {
|
||||
dEditPlayers.add((DEditPlayer) player);
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.github.dre2n.dungeonsxl.task;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
@ -27,7 +27,7 @@ public class UpdateTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) {
|
||||
for (DInstancePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDInstancePlayers()) {
|
||||
dPlayer.update(false);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user