2016-03-01 22:08:07 +01:00
|
|
|
/*
|
2022-01-08 23:02:57 +01:00
|
|
|
* Copyright (C) 2012-2022 Frank Baumann
|
2016-03-01 22:08:07 +01: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.command;
|
2016-03-01 22:08:07 +01:00
|
|
|
|
2018-05-08 21:34:37 +02:00
|
|
|
import de.erethon.caliburn.CaliburnAPI;
|
|
|
|
import de.erethon.caliburn.item.ExItem;
|
|
|
|
import de.erethon.caliburn.item.VanillaItem;
|
2018-05-03 21:54:25 +02:00
|
|
|
import de.erethon.dungeonsxl.DungeonsXL;
|
|
|
|
import de.erethon.dungeonsxl.config.DMessage;
|
|
|
|
import de.erethon.dungeonsxl.global.DPortal;
|
|
|
|
import de.erethon.dungeonsxl.player.DGamePlayer;
|
|
|
|
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
|
|
|
import de.erethon.dungeonsxl.player.DPermission;
|
2022-04-03 18:09:12 +02:00
|
|
|
import de.erethon.bedrock.chat.MessageUtil;
|
2016-03-01 22:08:07 +01:00
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Frank Baumann, Daniel Saukel
|
|
|
|
*/
|
2018-08-18 16:52:51 +02:00
|
|
|
public class PortalCommand extends DCommand {
|
2016-04-29 01:24:59 +02:00
|
|
|
|
2018-05-08 21:34:37 +02:00
|
|
|
CaliburnAPI caliburn = plugin.getCaliburn();
|
2017-10-04 23:57:12 +02:00
|
|
|
|
2018-08-18 16:52:51 +02:00
|
|
|
public PortalCommand(DungeonsXL plugin) {
|
|
|
|
super(plugin);
|
2016-03-01 22:08:07 +01:00
|
|
|
setCommand("portal");
|
|
|
|
setMinArgs(0);
|
2020-04-05 15:00:39 +02:00
|
|
|
setMaxArgs(2);
|
2020-02-02 03:03:29 +01:00
|
|
|
setHelp(DMessage.CMD_PORTAL_HELP.getMessage());
|
2017-11-16 18:25:10 +01:00
|
|
|
setPermission(DPermission.PORTAL.getNode());
|
2016-03-01 22:08:07 +01:00
|
|
|
setPlayerCommand(true);
|
|
|
|
}
|
2016-04-29 01:24:59 +02:00
|
|
|
|
2016-03-01 22:08:07 +01:00
|
|
|
@Override
|
|
|
|
public void onExecute(String[] args, CommandSender sender) {
|
|
|
|
Player player = (Player) sender;
|
2020-03-09 21:19:27 +01:00
|
|
|
DGlobalPlayer dGlobalPlayer = (DGlobalPlayer) dPlayers.get(player);
|
2016-04-29 01:24:59 +02:00
|
|
|
|
2016-05-05 14:13:28 +02:00
|
|
|
if (dGlobalPlayer instanceof DGamePlayer) {
|
2017-07-21 18:33:21 +02:00
|
|
|
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
|
2016-03-27 21:28:55 +02:00
|
|
|
return;
|
2016-03-01 22:08:07 +01:00
|
|
|
}
|
2016-04-29 01:24:59 +02:00
|
|
|
|
2018-05-08 21:34:37 +02:00
|
|
|
ExItem material = null;
|
2016-08-01 19:08:23 +02:00
|
|
|
|
|
|
|
if (args.length == 2) {
|
2018-05-08 21:34:37 +02:00
|
|
|
material = caliburn.getExItem(args[1]);
|
2016-08-01 19:08:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (material == null) {
|
2018-07-13 23:31:15 +02:00
|
|
|
material = VanillaItem.NETHER_PORTAL;
|
2016-08-01 19:08:23 +02:00
|
|
|
}
|
|
|
|
|
2016-03-27 21:28:55 +02:00
|
|
|
DPortal dPortal = dGlobalPlayer.getPortal();
|
2016-04-29 01:24:59 +02:00
|
|
|
|
2016-03-01 22:08:07 +01:00
|
|
|
if (dPortal == null) {
|
2018-08-18 16:52:51 +02:00
|
|
|
dPortal = new DPortal(plugin, plugin.getGlobalProtectionCache().generateId(DPortal.class, player.getWorld()), player.getWorld(), material, false);
|
2021-04-08 00:06:37 +02:00
|
|
|
plugin.getGlobalProtectionCache().addProtection(dPortal);
|
2016-03-27 21:28:55 +02:00
|
|
|
dGlobalPlayer.setCreatingPortal(dPortal);
|
2020-04-05 15:00:39 +02:00
|
|
|
dGlobalPlayer.setCachedItem(player.getInventory().getItemInHand());
|
2018-05-08 21:34:37 +02:00
|
|
|
player.getInventory().setItemInHand(VanillaItem.WOODEN_SWORD.toItemStack());
|
2017-07-21 18:33:21 +02:00
|
|
|
MessageUtil.sendMessage(player, DMessage.PLAYER_PORTAL_INTRODUCTION.getMessage());
|
2016-04-29 01:24:59 +02:00
|
|
|
|
2016-03-01 22:08:07 +01:00
|
|
|
} else {
|
2021-02-26 20:13:41 +01:00
|
|
|
if (args.length == 3 && VanillaItem.NETHER_PORTAL.getId().equalsIgnoreCase(args[1])) {
|
2020-04-05 15:00:39 +02:00
|
|
|
if (args[2].equalsIgnoreCase("-rotate")) {
|
|
|
|
dPortal.rotate();
|
|
|
|
}
|
|
|
|
dGlobalPlayer.setCreatingPortal(null);
|
|
|
|
MessageUtil.sendMessage(player, DMessage.PLAYER_PORTAL_CREATED.getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-27 21:28:55 +02:00
|
|
|
dPortal.delete();
|
|
|
|
dGlobalPlayer.setCreatingPortal(null);
|
2020-04-05 15:00:39 +02:00
|
|
|
player.getInventory().setItemInHand(dGlobalPlayer.getCachedItem());
|
2017-02-20 18:55:56 +01:00
|
|
|
dGlobalPlayer.setCachedItem(null);
|
2017-07-21 18:33:21 +02:00
|
|
|
MessageUtil.sendMessage(player, DMessage.PLAYER_PORTAL_ABORT.getMessage());
|
2016-03-01 22:08:07 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-29 01:24:59 +02:00
|
|
|
|
2016-03-01 22:08:07 +01:00
|
|
|
}
|