DungeonsXL/core/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java

98 lines
3.4 KiB
Java
Raw Normal View History

2016-04-28 22:41:14 +02:00
/*
2023-09-28 19:16:23 +02:00
* Copyright (C) 2012-2023 Frank Baumann
2016-04-28 22:41:14 +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.command;
2016-04-28 22:41:14 +02:00
2018-08-18 16:52:51 +02:00
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.dungeon.Game;
2021-02-27 22:37:39 +01:00
import de.erethon.dungeonsxl.api.event.group.GroupCreateEvent.Cause;
import de.erethon.dungeonsxl.api.player.PlayerGroup;
2018-05-03 21:54:25 +02:00
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGamePlayer;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.player.DPermission;
2022-04-03 18:09:12 +02:00
import de.erethon.bedrock.chat.MessageUtil;
import org.bukkit.Bukkit;
2016-04-28 22:41:14 +02:00
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author Daniel Saukel
*/
2018-08-18 16:52:51 +02:00
public class EnterCommand extends DCommand {
2016-04-28 22:41:14 +02:00
2018-08-18 16:52:51 +02:00
public EnterCommand(DungeonsXL plugin) {
super(plugin);
2016-04-28 22:41:14 +02:00
setMinArgs(1);
setMaxArgs(2);
setCommand("enter");
setHelp(DMessage.CMD_ENTER_HELP.getMessage());
2017-11-16 18:25:10 +01:00
setPermission(DPermission.ENTER.getNode());
2016-04-28 22:41:14 +02:00
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player captain = (Player) sender;
String targetName = args.length == 3 ? args[2] : args[1];
PlayerGroup joining = args.length == 3 ? plugin.getGroupCache().get(args[1]) : plugin.getPlayerGroup(captain);
PlayerGroup target = plugin.getGroupCache().get(targetName);
2016-04-28 22:41:14 +02:00
if (target == null) {
Player targetPlayer = Bukkit.getPlayer(targetName);
if (targetPlayer != null) {
target = plugin.getPlayerGroup(targetPlayer);
}
}
2016-04-28 22:41:14 +02:00
if (target == null) {
2017-07-21 18:33:21 +02:00
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_GROUP.getMessage(targetName));
2016-04-28 22:41:14 +02:00
return;
}
Game game = target.getGame();
2016-04-28 22:41:14 +02:00
if (game == null) {
2017-07-21 18:33:21 +02:00
MessageUtil.sendMessage(sender, DMessage.ERROR_NOT_IN_GAME.getMessage(targetName));
2016-04-28 22:41:14 +02:00
return;
}
2020-04-18 17:32:52 +02:00
if (joining != null && joining.getGame() != null) {
2017-07-21 18:33:21 +02:00
MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GAME.getMessage());
2016-04-28 22:41:14 +02:00
return;
}
if (joining == null) {
2021-02-27 22:37:39 +01:00
joining = DGroup.create(plugin, Cause.COMMAND, captain, null, null, game.getDungeon());
}
if (joining == null) {
return;
2016-04-28 22:41:14 +02:00
}
if (joining.getLeader() != captain && !DPermission.hasPermission(sender, DPermission.BYPASS)) {
MessageUtil.sendMessage(sender, DMessage.ERROR_NOT_LEADER.getMessage());
2016-04-28 22:41:14 +02:00
return;
}
game.addGroup(joining);
2017-07-21 18:33:21 +02:00
joining.sendMessage(DMessage.CMD_ENTER_SUCCESS.getMessage(joining.getName(), target.getName()));
2016-04-28 22:41:14 +02:00
for (Player player : joining.getMembers().getOnlinePlayers()) {
new DGamePlayer(plugin, player, game.getWorld());
2016-04-28 22:41:14 +02:00
}
}
}