82 lines
2.2 KiB
Java
82 lines
2.2 KiB
Java
package eu.univento.core.commands;
|
|
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.AutoCommand;
|
|
import eu.univento.core.api.languages.Messages;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.core.api.player.Perms.Ranks;
|
|
import eu.univento.core.api.server.ServerSettings;
|
|
import org.bukkit.GameMode;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* lets player build
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class Build extends AutoCommand<Core>{
|
|
|
|
/**
|
|
* player who can build
|
|
*/
|
|
private static HashMap<CustomPlayer, ItemStack[]> players = new HashMap<>();
|
|
|
|
/**
|
|
* @return player that can build
|
|
*/
|
|
public static HashMap<CustomPlayer, ItemStack[]> getPlayers() {
|
|
return players;
|
|
}
|
|
|
|
/**
|
|
* @param plugin main class
|
|
* @param command command to execute
|
|
* @param description describes the command
|
|
* @param aliases aliases of command
|
|
*/
|
|
public Build(Core plugin, String command, String description, String[] aliases) {
|
|
super(plugin, command, description, aliases);
|
|
}
|
|
|
|
@Override
|
|
public boolean execute(CommandSender sender, String label, String[] args) {
|
|
if(sender instanceof Player) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
|
Messages msgs = new Messages(p);
|
|
if(p.isAllowed(Ranks.Builder)) {
|
|
if(players.containsKey(p)) {
|
|
p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_OFF());
|
|
|
|
ItemStack[] content = players.get(p);
|
|
p.getInventory().setContents(content);
|
|
players.remove(p);
|
|
p.setGameMode(ServerSettings.getGameMode());
|
|
|
|
}else {
|
|
players.put(p, p.getInventory().getContents());
|
|
p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_ON());
|
|
p.getInventory().clear();
|
|
p.setGameMode(GameMode.CREATIVE);
|
|
}
|
|
}else {
|
|
sender.sendMessage(msgs.NO_PERMS());
|
|
}
|
|
}else {
|
|
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
} |