2016-03-27 21:28:55 +02:00
|
|
|
/*
|
2022-01-08 23:02:57 +01:00
|
|
|
* Copyright (C) 2012-2022 Frank Baumann
|
2016-03-27 21:28:55 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2018-05-03 21:54:25 +02:00
|
|
|
package de.erethon.dungeonsxl.player;
|
2016-03-27 21:28:55 +02:00
|
|
|
|
2018-05-03 21:54:25 +02:00
|
|
|
import de.erethon.dungeonsxl.DungeonsXL;
|
2020-03-09 21:19:27 +01:00
|
|
|
import de.erethon.dungeonsxl.api.player.EditPlayer;
|
|
|
|
import de.erethon.dungeonsxl.api.world.EditWorld;
|
2018-05-03 21:54:25 +02:00
|
|
|
import de.erethon.dungeonsxl.config.DMessage;
|
2022-04-03 18:09:12 +02:00
|
|
|
import de.erethon.bedrock.chat.MessageUtil;
|
|
|
|
import de.erethon.bedrock.misc.ProgressBar;
|
2017-02-20 01:46:55 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2016-05-06 23:53:59 +02:00
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.Sign;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.block.SignChangeEvent;
|
2016-12-03 13:30:47 +01:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2016-05-06 23:53:59 +02:00
|
|
|
|
2016-03-27 21:28:55 +02:00
|
|
|
/**
|
|
|
|
* @author Daniel Saukel
|
|
|
|
*/
|
2020-03-09 21:19:27 +01:00
|
|
|
public class DEditPlayer extends DInstancePlayer implements EditPlayer {
|
2016-05-06 23:53:59 +02:00
|
|
|
|
|
|
|
private String[] linesCopy;
|
2020-03-09 21:19:27 +01:00
|
|
|
private EditWorld editWorld;
|
2016-05-06 23:53:59 +02:00
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
public DEditPlayer(DungeonsXL plugin, Player player, EditWorld world) {
|
|
|
|
super(plugin, player, world);
|
2016-12-27 00:55:43 +01:00
|
|
|
editWorld = world;
|
2016-05-06 23:53:59 +02:00
|
|
|
|
2016-12-03 13:30:47 +01:00
|
|
|
// Set gamemode a few ticks later to avoid incompatibilities with plugins that force a gamemode
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
player.setGameMode(GameMode.CREATIVE);
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, 10L);
|
|
|
|
|
2016-05-06 23:53:59 +02:00
|
|
|
clearPlayerData();
|
|
|
|
|
2016-07-08 20:41:04 +02:00
|
|
|
Location teleport = world.getLobbyLocation();
|
2016-05-06 23:53:59 +02:00
|
|
|
if (teleport == null) {
|
2020-06-28 01:06:59 +02:00
|
|
|
player.teleport(world.getWorld().getSpawnLocation());
|
2016-05-06 23:53:59 +02:00
|
|
|
} else {
|
2020-06-28 01:06:59 +02:00
|
|
|
player.teleport(teleport);
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
2016-05-07 01:08:45 +02:00
|
|
|
|
|
|
|
// Permission bridge
|
|
|
|
if (plugin.getPermissionProvider() != null) {
|
2017-10-04 23:57:12 +02:00
|
|
|
for (String permission : plugin.getMainConfig().getEditPermissions()) {
|
2020-10-16 14:38:21 +02:00
|
|
|
plugin.getPermissionProvider().playerAddTransient(getWorld().getName(), player, permission);
|
2016-05-07 01:08:45 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
|
|
|
|
2016-07-08 20:41:04 +02:00
|
|
|
|
2016-05-06 23:53:59 +02:00
|
|
|
/* Getters and setters */
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
|
|
|
public EditWorld getEditWorld() {
|
|
|
|
return editWorld;
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
|
|
|
public String[] getCopiedLines() {
|
|
|
|
return linesCopy;
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
|
|
|
public void setCopiedLines(String[] linesCopy) {
|
|
|
|
this.linesCopy = linesCopy;
|
2016-12-27 00:55:43 +01:00
|
|
|
}
|
|
|
|
|
2016-05-06 23:53:59 +02:00
|
|
|
/* Actions */
|
2016-05-07 01:08:45 +02:00
|
|
|
@Override
|
|
|
|
public void delete() {
|
|
|
|
// Permission bridge
|
|
|
|
if (plugin.getPermissionProvider() != null) {
|
2017-10-04 23:57:12 +02:00
|
|
|
for (String permission : plugin.getMainConfig().getEditPermissions()) {
|
2016-05-07 01:08:45 +02:00
|
|
|
plugin.getPermissionProvider().playerRemoveTransient(getWorld().getName(), player, permission);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.delete();
|
|
|
|
}
|
|
|
|
|
2016-05-06 23:53:59 +02:00
|
|
|
/**
|
2016-06-26 12:21:32 +02:00
|
|
|
* Escape the DEditWorld without saving.
|
2016-05-06 23:53:59 +02:00
|
|
|
*/
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2016-05-06 23:53:59 +02:00
|
|
|
public void escape() {
|
|
|
|
delete();
|
2016-07-26 19:47:55 +02:00
|
|
|
reset(false);
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-02-20 01:46:55 +01:00
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
2016-05-06 23:53:59 +02:00
|
|
|
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;
|
2017-07-21 18:33:21 +02:00
|
|
|
MessageUtil.sendMessage(getPlayer(), DMessage.PLAYER_SIGN_COPIED.getMessage());
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String info = "" + block.getType();
|
|
|
|
if (block.getData() != 0) {
|
|
|
|
info = info + "," + block.getData();
|
|
|
|
}
|
2017-07-21 18:33:21 +02:00
|
|
|
MessageUtil.sendMessage(getPlayer(), DMessage.PLAYER_BLOCK_INFO.getMessage(info));
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-11-02 21:17:19 +01:00
|
|
|
public void leave(boolean unloadIfEmpty) {
|
2016-05-07 01:08:45 +02:00
|
|
|
delete();
|
|
|
|
|
2016-07-26 19:47:55 +02:00
|
|
|
reset(false);
|
2016-05-06 23:53:59 +02:00
|
|
|
|
2020-11-02 21:17:19 +01:00
|
|
|
if (unloadIfEmpty && !plugin.isLoadingWorld() && editWorld != null && editWorld.getPlayers().isEmpty()) {
|
2021-07-08 17:42:53 +02:00
|
|
|
plugin.setLoadingWorld(true);
|
2020-05-01 13:54:09 +02:00
|
|
|
editWorld.delete();
|
2020-10-30 17:10:48 +01:00
|
|
|
new ProgressBar(player, config.getEditInstanceRemovalDelay()) {
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
MessageUtil.sendActionBarMessage(player, DMessage.CMD_SAVE_SUCCESS.getMessage());
|
2021-07-08 17:42:53 +02:00
|
|
|
plugin.setLoadingWorld(false);
|
2020-10-30 17:10:48 +01:00
|
|
|
}
|
|
|
|
}.send(plugin);
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-05-10 23:19:18 +02:00
|
|
|
public void update() {
|
|
|
|
if (player.getWorld().equals(getWorld())) {
|
2016-05-07 01:08:45 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-05-10 23:19:18 +02:00
|
|
|
plugin.log("Player " + this + " was expected to be in " + getWorld() + " but is in " + player.getWorld());
|
|
|
|
Location teleportLocation;
|
|
|
|
if (editWorld.getLobbyLocation() != null) {
|
|
|
|
teleportLocation = editWorld.getLobbyLocation();
|
|
|
|
} else {
|
|
|
|
teleportLocation = getWorld().getSpawnLocation();
|
2016-05-07 01:08:45 +02:00
|
|
|
}
|
2021-05-10 23:19:18 +02:00
|
|
|
|
|
|
|
plugin.log("Teleporting to " + teleportLocation);
|
|
|
|
player.teleport(teleportLocation);
|
2016-05-06 23:53:59 +02:00
|
|
|
}
|
|
|
|
|
2016-03-27 21:28:55 +02:00
|
|
|
}
|