123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- package me.km.plots;
- import com.mojang.authlib.GameProfile;
- import java.util.HashMap;
- import java.util.UUID;
- 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.chatmanager.ChatManager;
- import me.km.dimensions.ModDimensions;
- import me.km.permissions.Permissions;
- import me.km.playerbank.PlayerBank;
- import me.km.utils.SpecialBlockUtils;
- import net.minecraft.block.Block;
- import net.minecraft.command.ICommandSender;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.tileentity.TileEntitySign;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- public class CommandPlot extends ModuleCommand
- {
- public final HashMap<UUID, BlockPos> coord1;
- public final HashMap<UUID, BlockPos> coord2;
- private final ProtectionBank bank;
-
- public CommandPlot(Module m)
- {
- super("plot", m);
- super.setDescription("Zeigt alles für die Plot-Verwaltung");
- super.setUsage("/plot für die Hilfe");
- super.setPermission(Permissions.PLOT);
- super.addAlias("p");
- super.addAlias("pl");
- super.addAlias("plo");
-
- coord1 = new HashMap<>();
- coord2 = new HashMap<>();
-
- bank = KajetansMod.plots.getDataBank(ProtectionBank.class);
- }
- @Override
- public boolean execute(ICommandSender cs, String[] arg)
- {
- Module m = this.getModule();
-
- if(arg.length >= 1)
- {
- // Abkürzungen
- switch(arg[0].toLowerCase())
- {
- case "a":
- case "c":
- case "create":
- case "add":
- {
- if(!KajetansMod.perms.has(cs, Permissions.PLOT_CREATE))
- {
- break;
- }
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.onlyPlayer());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- if(coord1.containsKey(p.getUniqueID()) && coord2.containsKey(p.getUniqueID()))
- {
- BlockPos l1 = coord1.get(p.getUniqueID());
- BlockPos l2 = coord2.get(p.getUniqueID());
- bank.addPlot(Math.min(l1.getX(), l2.getX()),
- 30,
- Math.min(l1.getZ(), l2.getZ()),
- Math.max(l1.getX(), l2.getX()),
- 255,
- Math.max(l1.getZ(), l2.getZ()),
- ModDimensions.getWorldName(p.world), p, arg.length >= 2 ? arg[1] : null);
- return true;
- }
- m.send(cs, "Du musst zwei Punkte wählen. (Holzschwert + Creative)");
- return true;
- }
- case "create3d":
- case "add3d":
- {
- if(!KajetansMod.perms.has(cs, Permissions.PLOT_CREATE))
- {
- break;
- }
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.onlyPlayer());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- if(coord1.containsKey(p.getUniqueID()) && coord2.containsKey(p.getUniqueID()))
- {
- BlockPos l1 = coord1.get(p.getUniqueID());
- BlockPos l2 = coord2.get(p.getUniqueID());
- bank.addPlot(Math.min(l1.getX(), l2.getX()),
- Math.min(l1.getY(), l2.getY()),
- Math.min(l1.getZ(), l2.getZ()),
- Math.max(l1.getX(), l2.getX()),
- Math.max(l1.getY(), l2.getY()),
- Math.max(l1.getZ(), l2.getZ()),
- ModDimensions.getWorldName(p.world), p, arg.length >= 2 ? arg[1] : null);
- return true;
- }
- m.send(cs, "Du musst zwei Punkte wählen. (Holzschwert + Creative)");
- return true;
- }
- case "e":
- case "expand":
- {
- if(!KajetansMod.perms.has(cs, Permissions.PLOT_CREATE) || arg.length < 2)
- {
- break;
- }
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.onlyPlayer());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- if(coord1.containsKey(p.getUniqueID()) && coord2.containsKey(p.getUniqueID()))
- {
- UUID uuid = p.getUniqueID();
- BlockPos l1 = coord1.get(uuid);
- BlockPos l2 = coord2.get(uuid);
- int x1 = l1.getX();
- int y1 = l1.getY();
- int z1 = l1.getZ();
- int x2 = l2.getX();
- int y2 = l2.getY();
- int z2 = l2.getZ();
- int helper;
- if(x1 > x2)
- {
- helper = x1;
- x1 = x2;
- x2 = helper;
- }
- if(y1 > y2)
- {
- helper = y1;
- y1 = y2;
- y2 = helper;
- }
- if(z1 > z2)
- {
- helper = z1;
- z1 = z2;
- z2 = helper;
- }
- float yaw = p.rotationYaw;
- float pitch = p.rotationPitch;
- int expandRate;
- try
- {
- expandRate = Integer.parseInt(arg[1]);
- if(expandRate <= 0)
- {
- throw new NumberFormatException();
- }
- }
- catch(NumberFormatException ex)
- {
- m.send(cs, GlobalText.noPositiveNaturalNumber());
- return true;
- }
- String richtung = "FEHLER";
- if(pitch >= 75)
- {
- y1 -= expandRate;
- if( y1 < 0)
- {
- y1 = 0;
- }
- richtung = "unten";
- }
- else if(pitch <= -75)
- {
- y2 += expandRate;
- if(y2 > 255)
- {
- y2 = 255;
- }
- richtung = "oben";
- }
- else if(yaw >= 45 && yaw < 135)
- {
- x1 -= expandRate;
- richtung = "Westen";
- }
- else if(yaw >= 135 && yaw < 225)
- {
- z1 -= expandRate;
- richtung = "Norden";
- }
- else if(yaw >= 225 && yaw < 315)
- {
- x2 += expandRate;
- richtung = "Osten";
- }
- else if(yaw >= 315 || yaw < 45)
- {
- z2 += expandRate;
- richtung = "Süden";
- }
- coord1.put(uuid, new BlockPos(x1, y1, z1));
- coord2.put(uuid, new BlockPos(x2, y2, z2));
- m.send(cs, "Der Plot wurde um " + expandRate + " nach " + richtung + " erweitert.");
- return true;
- }
- m.send(cs, "Du musst zwei Punkte wählen. (Holzschwert + Creative)");
- return true;
- }
- case "name":
- {
- if(!KajetansMod.perms.has(cs, Permissions.PLOT_CREATE) || arg.length < 2)
- {
- break;
- }
- int id;
- try
- {
- id = Integer.parseInt(arg[1]);
- if(id < 0)
- {
- m.send(cs, GlobalText.noNaturalNumber());
- return true;
- }
- bank.changeName(id, ChatManager.colorMessage(Utils.connectSpaces(arg, 2), cs), cs);
- }
- catch(NumberFormatException ex)
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.missingParameter());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- bank.changeName(bank.getFirstRegionId(p), ChatManager.colorMessage(Utils.connectSpaces(arg, 1), p), p);
- }
- return true;
- }
- case "i":
- case "info":
- {
- if(KajetansMod.perms.has(cs, Permissions.PLOT_INFO))
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.onlyPlayer());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- bank.printInfo(p);
- return true;
- }
- break;
- }
- case "r":
- case "remove":
- case "delete":
- {
- if(KajetansMod.perms.has(cs, Permissions.PLOT_CREATE))
- {
- Integer id;
- if(arg.length >= 2)
- {
- try
- {
- id = Integer.parseInt(arg[1]);
- if(id < 0)
- {
- throw new NumberFormatException();
- }
- }
- catch(NumberFormatException ex)
- {
- m.send(cs, GlobalText.noNaturalNumber());
- return true;
- }
- }
- else
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.missingParameter());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- id = bank.getFirstRegionId(p);
- }
- bank.removePlot(id, cs);
- return true;
- }
- break;
- }
- case "at":
- case "addtag":
- {
- if(KajetansMod.perms.has(cs, Permissions.PLOT_TAG) && arg.length >= 2)
- {
- Integer id;
- if(arg.length >= 3)
- {
- try
- {
- id = Integer.parseInt(arg[2]);
- if(id < 0)
- {
- throw new NumberFormatException();
- }
- }
- catch(NumberFormatException ex)
- {
- m.send(cs, GlobalText.noNaturalNumber());
- return true;
- }
- }
- else
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.missingParameter());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- id = bank.getFirstRegionId(p);
- }
- bank.addTag(id, arg[1], cs);
- return true;
- }
- break;
- }
- case "rt":
- case "removetag":
- {
- if(KajetansMod.perms.has(cs, Permissions.PLOT_TAG) && arg.length >= 2)
- {
- Integer id;
- if(arg.length >= 3)
- {
- try
- {
- id = Integer.parseInt(arg[2]);
- if(id < 0)
- {
- throw new NumberFormatException();
- }
- }
- catch(NumberFormatException ex)
- {
- m.send(cs, GlobalText.noNaturalNumber());
- return true;
- }
- }
- else
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.missingParameter());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- id = bank.getFirstRegionId(p);
- }
- bank.removeTag(id, arg[1], cs);
- return true;
- }
- break;
- }
- case "share":
- {
- if(KajetansMod.perms.has(cs, Permissions.PLOT_SHARE) && arg.length >= 2)
- {
- Integer id;
- if(arg.length >= 3)
- {
- try
- {
- id = Integer.parseInt(arg[2]);
- if(id < 0)
- {
- throw new NumberFormatException();
- }
- }
- catch(NumberFormatException ex)
- {
- m.send(cs, GlobalText.noNaturalNumber());
- return true;
- }
- }
- else
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.missingParameter());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- id = bank.getFirstRegionId(p);
- }
- GameProfile player = KajetansMod.playerbank.getDataBank().getOfflinePlayer(arg[1]);
- if(player == null)
- {
- m.send(cs, GlobalText.cantFindPlayer(arg[1]));
- return true;
- }
- bank.addPlayer(id, player, cs);
- return true;
- }
- break;
- }
- case "kick":
- {
- if(KajetansMod.perms.has(cs, Permissions.PLOT_SHARE) && arg.length >= 2)
- {
- Integer id;
- if(arg.length >= 3)
- {
- try
- {
- id = Integer.parseInt(arg[2]);
- if(id < 0)
- {
- throw new NumberFormatException();
- }
- }
- catch(NumberFormatException ex)
- {
- m.send(cs, GlobalText.noNaturalNumber());
- return true;
- }
- }
- else
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.missingParameter());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- id = bank.getFirstRegionId(p);
- }
- GameProfile player = KajetansMod.playerbank.getDataBank(PlayerBank.class).getOfflinePlayer(arg[1]);
- if(player == null)
- {
- m.send(cs, GlobalText.cantFindPlayer(arg[1]));
- return true;
- }
- bank.removePlayer(id, player, cs);
- return true;
- }
- break;
- }
- case "sign":
- {
- if(KajetansMod.perms.has(cs, Permissions.PLOT_SIGN) && arg.length >= 3)
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.onlyPlayer());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- World w = p.world;
- BlockPos pos = Utils.getPlayerTarget(p, 20, true);
- Block b = w.getBlockState(pos).getBlock();
- if(b == Blocks.STANDING_SIGN || b == Blocks.WALL_SIGN)
- {
- TileEntitySign sign = (TileEntitySign) w.getTileEntity(pos);
- if(sign == null)
- {
- this.getModule().send(cs, GlobalText.shouldNotHappen());
- return true;
- }
- int i;
- try
- {
- i = Integer.parseInt(arg[1]);
- if(i < 0)
- {
- throw new NumberFormatException();
- }
- }
- catch(NumberFormatException ex)
- {
- m.send(cs, GlobalText.cantFindPlayer(GlobalText.noNaturalNumber()));
- return true;
- }
- try
- {
- int id = Integer.parseInt(arg[2]);
- if(id < 0)
- {
- throw new NumberFormatException();
- }
- if(!bank.doesPlotExist(id))
- {
- m.send(p, "Der Plot mit der ID '" + id + "' ist nicht vorhanden.");
- return true;
- }
- SpecialBlockUtils.setSignLine(sign, 0, "§0[§6Plot§0]", false);
- SpecialBlockUtils.setSignLine(sign, 1, "§2" + arg[1] + " Emeralds", false);
- SpecialBlockUtils.setSignLine(sign, 1, arg[2], true);
- return true;
- }
- catch(NumberFormatException ex)
- {
- m.send(cs, GlobalText.noNaturalNumber());
- return true;
- }
- }
- m.send(cs, "Du bist nicht auf ein Schild gerichtet.");
- return true;
- }
- break;
- }
- }
- }
- // Help Menu
- m.send(cs, "/plot ...");
- if(KajetansMod.perms.has(cs, Permissions.PLOT_INFO))
- {
- m.sendHelpListElement(cs, "info", "Gibt Infos über die aktuelle Position");
- }
- if(KajetansMod.perms.has(cs, Permissions.PLOT_CREATE))
- {
- m.sendHelpListElement(cs, "create [player]", "Erstellt ein Plot (30 - 255)");
- m.sendHelpListElement(cs, "create3D [player]", "Erstellt ein Plot");
- m.sendHelpListElement(cs, "remove [id]", "Entfernt ein Plot");
- m.sendHelpListElement(cs, "expand <blocks>", "Erweitert die aktuelle Auswahl");
- m.sendHelpListElement(cs, "name [id] <name>", "Gibt einem Plot einen Namen");
- }
- if(KajetansMod.perms.has(cs, Permissions.PLOT_TAG))
- {
- m.sendHelpListElement(cs, "addtag <tag> [id]", "Fügt einen Tag hinzu");
- m.sendHelpListElement(cs, "removetag <tag> [id]", "Entfernt einen Tag");
- }
- if(KajetansMod.perms.has(cs, Permissions.PLOT_SHARE))
- {
- m.sendHelpListElement(cs, "share <player> [id]", "Fügt einen Spieler hinzu");
- m.sendHelpListElement(cs, "kick <player> [id]", "Entfernt einen Spieler");
- }
- if(KajetansMod.perms.has(cs, Permissions.PLOT_SIGN))
- {
- m.sendHelpListElement(cs, "sign <price> <id>", "Ändert ein Schild zum Verkaufsschild");
- }
- return true;
- }
- }
|