123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- package me.km.blockprotections;
- import com.mojang.authlib.GameProfile;
- import me.km.KajetansMod;
- import me.km.api.GlobalText;
- import me.km.api.Module;
- import me.km.api.ModuleCommand;
- import me.km.api.Utils;
- import me.km.permissions.Permissions;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockDoor;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.command.ICommandSender;
- import net.minecraft.entity.player.EntityPlayerMP;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- public class CommandBlock extends ModuleCommand
- {
- private final BlockProtectionBank bank;
- //private int counter;
- //private List<Location> locs;
- //private final ArrayList<BlockState> blocks;
- //private boolean checker;
-
- public CommandBlock(Module m)
- {
- super("block", m);
- super.setDescription("Zeigt alles für die Block-Verwaltung");
- super.setUsage("/block für die Hilfe");
- super.setPermission(Permissions.BLOCK);
- super.addAlias("blocks");
- super.addAlias("pro");
- super.addAlias("protect");
-
- bank = KajetansMod.blocks.getDataBank(BlockProtectionBank.class);
- //locs = new ArrayList<>();
- //blocks = new ArrayList<>();
- }
-
- @Override
- public boolean execute(ICommandSender cs, String[] arg)
- {
- if(!(cs instanceof EntityPlayerMP))
- {
- this.getModule().send(cs, GlobalText.onlyPlayer());
- return true;
- }
- Module m = this.getModule();
- EntityPlayerMP p = (EntityPlayerMP) cs;
- World w = p.getEntityWorld();
- if(!KajetansMod.worldManager.getWorldPreferences(w).blockProtection && !KajetansMod.perms.has(cs, Permissions.BLOCK_BYPASS))
- {
- m.send(cs, "Du darfst hier keine Blöcke schützen.");
- return true;
- }
- if(arg.length > 0)
- {
- BlockPos pos = Utils.getPlayerTarget(p);
- IBlockState state = w.getBlockState(pos);
- Block b = state.getBlock();
- if(!Utils.shouldBeProtected(b) && !KajetansMod.perms.has(cs, Permissions.BLOCK_ALL))
- {
- m.send(cs, "Du kannst diesen Block nicht bearbeiten.");
- m.send(cs, "Du bist auf folgenden Block gerichtet: " + b.toString());
- return true;
- }
- if(Utils.getStateValue(state, BlockDoor.HALF) == BlockDoor.EnumDoorHalf.UPPER)
- {
- pos = pos.add(0, -1, 0);
- }
- switch(arg[0])
- {
- case "protect":
- {
- String name = null;
- if(arg.length >= 2 && KajetansMod.perms.has(cs, Permissions.BLOCK_OTHER))
- {
- name = arg[1];
- }
- bank.addBlock(pos, w, p, name);
- if(b != Blocks.CHEST && b != Blocks.TRAPPED_CHEST)
- {
- return true;
- }
- BlockPos otherChest = Utils.getSameNearbyBlock(w, pos, b);
- if(otherChest != null)
- {
- bank.addBlock(otherChest, w, p, name);
- }
- return true;
- }
- case "remove":
- {
- if(!bank.doesExist(pos, w))
- {
- this.getModule().send(p, "Der Block ist nicht gesichert.");
- return true;
- }
- if(!bank.hasAccess(pos, w, p, false) && !KajetansMod.perms.has(cs, Permissions.BLOCK_BYPASS))
- {
- m.send(cs, "Du hast keinen Zugriff auf diesen Block.");
- return true;
- }
- bank.removeBlock(pos, w, p);
- if(b != Blocks.CHEST && b != Blocks.TRAPPED_CHEST)
- {
- return true;
- }
- BlockPos otherChest = Utils.getSameNearbyBlock(w, pos, b);
- if(otherChest != null)
- {
- bank.removeBlock(otherChest, w, p);
- }
- return true;
- }
- case "info":
- {
- bank.printInfo(pos, w, p);
- return true;
- }
- case "share":
- {
- if(arg.length >= 2)
- {
- if(!bank.doesExist(pos, w))
- {
- this.getModule().send(p, "Der Block ist nicht gesichert.");
- return true;
- }
- if(!bank.hasAccess(pos, w, p, false) && !KajetansMod.perms.has(cs, Permissions.BLOCK_BYPASS))
- {
- m.send(cs, "Du hast keinen Zugriff auf diesen Block.");
- return true;
- }
- GameProfile player = KajetansMod.playerbank.getDataBank().getOfflinePlayer(arg[1]);
- if(player == null)
- {
- m.send(cs, GlobalText.cantFindPlayer(arg[1]));
- return true;
- }
- bank.addPlayer(pos, w, player, p);
- if(b != Blocks.CHEST && b != Blocks.TRAPPED_CHEST)
- {
- return true;
- }
- BlockPos otherChest = Utils.getSameNearbyBlock(w, pos, b);
- if(otherChest != null)
- {
- bank.addPlayer(otherChest, w, player, p);
- }
- return true;
- }
- }
- case "kick":
- {
- if(arg.length >= 2)
- {
- if(!bank.doesExist(pos, w))
- {
- this.getModule().send(p, "Der Block ist nicht gesichert.");
- return true;
- }
- if(!bank.hasAccess(pos, w, p, true) && !KajetansMod.perms.has(cs, Permissions.BLOCK_BYPASS))
- {
- m.send(cs, "Du hast keinen Zugriff auf diesen Block.");
- return true;
- }
- GameProfile player = KajetansMod.playerbank.getDataBank().getOfflinePlayer(arg[1]);
- if(player == null)
- {
- m.send(cs, GlobalText.cantFindPlayer(arg[1]));
- return true;
- }
- bank.removePlayer(pos, w, player, p);
- if(b != Blocks.CHEST && b != Blocks.TRAPPED_CHEST)
- {
- return true;
- }
- BlockPos otherChest = Utils.getSameNearbyBlock(w, pos, b);
- if(otherChest != null)
- {
- bank.removePlayer(otherChest, w, player, p);
- }
- return true;
- }
- }
- case "clear":
- {
- if(KajetansMod.perms.has(cs, Permissions.BLOCK_CLEAR))
- {
- //TODO
- this.getModule().send(cs, GlobalText.notImplementedYet());
- /*checker = false;
- Bukkit.getScheduler().runTaskAsynchronously(this.getModule().getPlugin(), () ->
- {
- counter = 0;
- locs = bank.getAll();
- checker = true;
- });
- Bukkit.getScheduler().scheduleSyncDelayedTask(this.getModule().getPlugin(), () ->
- {
- if(!checker)
- {
- this.getModule().send(cs, "Das Abrufen aller Einträge hat zu lange gedauert.");
- locs.clear();
- blocks.clear();
- return;
- }
- locs.stream().forEach((l) ->
- {
- Bukkit.getScheduler().scheduleSyncDelayedTask(this.getModule().getPlugin(), () ->
- {
- try
- {
- blocks.add(l.getBlock().getState());
- }
- catch(NullPointerException ex)
- {
- }
- });
- });
- }, 200);
- Bukkit.getScheduler().runTaskLaterAsynchronously(this.getModule().getPlugin(), () ->
- {
- blocks.stream().filter(bl -> !Utils.shouldBeProtected(bl)).forEach(bl ->
- {
- bank.removeBlock(bl.getLocation(), p);
- counter++;
- });
- this.getModule().send(cs, "Alle ungültigen Protections wurden entfernt. (" + counter + ")");
- locs.clear();
- blocks.clear();
- }, 400);*/
- return true;
- }
- break;
- }
- }
- }
- m.send(cs, "/block ...");
- m.sendHelpListElement(cs, "protect [player]", "Erstellt eine Block-Protection");
- m.sendHelpListElement(cs, "remove", "Löscht eine Block-Protection");
- m.sendHelpListElement(cs, "info", "Gibt Information über den Block");
- m.sendHelpListElement(cs, "share <player>", "Teilt eine Block-Protection mit einem Spieler");
- m.sendHelpListElement(cs, "kick <player>", "Kickt einen Spieler von einer Block-Protection");
- if(KajetansMod.perms.has(cs, Permissions.BLOCK_CLEAR))
- {
- m.sendHelpListElement(cs, "clear", "Entfernt ungültige Block-Protections auf jeden Block");
- }
- return true;
- }
- }
|