diff --git a/src/de/warking/bausystem/BauSystem.java b/src/de/warking/bausystem/BauSystem.java index e7f2516..3114acc 100644 --- a/src/de/warking/bausystem/BauSystem.java +++ b/src/de/warking/bausystem/BauSystem.java @@ -5,10 +5,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import de.pro_crafting.commandframework.CommandArgs; import de.pro_crafting.commandframework.CommandFramework; import de.pro_crafting.commandframework.Completer; -import de.warking.bausystem.commands.CommandBau; -import de.warking.bausystem.commands.CommandGamemode; -import de.warking.bausystem.commands.CommandGui; -import de.warking.bausystem.commands.CommandTeleport; +import de.warking.bausystem.commands.*; import de.warking.bausystem.config.Config; import de.warking.bausystem.world.LagDetectorRunnable; import de.warking.bausystem.world.RegionListener; @@ -82,7 +79,6 @@ public class BauSystem extends JavaPlugin implements Listener { getRegionData.set("regions.airship1.schematic.testblock", " "); getRegionData.set("regions.airship1.schematic.reset", " "); - saveRegionData(); } @@ -112,6 +108,8 @@ public class BauSystem extends JavaPlugin implements Listener { } cmdFramework.registerCommands(new CommandBau()); + cmdFramework.registerCommands(new CommandNV()); + cmdFramework.registerCommands(new CommandTrace()); Bukkit.getPluginManager().registerEvents(new RegionListener(this), this); Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { @@ -261,6 +259,8 @@ public class BauSystem extends JavaPlugin implements Listener { } attachment.setPermission("F3NPerm.use", true); attachment.setPermission("fawe.permpack.basic", true); + attachment.setPermission("worldedit.navigation.jumpto.tool", true); + attachment.setPermission("worldedit.navigation.thru.tool", true); } @EventHandler diff --git a/src/de/warking/bausystem/commands/CommandBau.java b/src/de/warking/bausystem/commands/CommandBau.java index ba7dc6f..7fce703 100644 --- a/src/de/warking/bausystem/commands/CommandBau.java +++ b/src/de/warking/bausystem/commands/CommandBau.java @@ -30,7 +30,7 @@ import java.util.UUID; public class CommandBau { - @Command(name = "bau", aliases = "gs") + @Command(name = "bau", aliases = "gs", inGameOnly = true) public void onBau(CommandArgs args) { onHelp(args); } @@ -67,6 +67,7 @@ public class CommandBau { p.sendMessage("§6/bau togglereset §7- Darf ein Spieler eine Region erneuern"); p.sendMessage("§6/bau togglereplace §7- Darf ein Spieler in einer Region replacen"); p.sendMessage("§6/bau togglechgm §7- Darf ein Spieler seinen Spielmodus ändern"); + p.sendMessage("§6/nv §7- Aktiviert/Deaktiviert Nachtsicht"); } @Command(name = "bau.home", aliases = "gs.home", inGameOnly = true) @@ -141,7 +142,7 @@ public class CommandBau { if (id == null) { p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spieler"); return; - }else if (Bauwelt.getBauwelt(id) == null && !p.hasPermission("bau.team")) { + }else if (BauweltMember.getBauMember(id, p.getUniqueId()) == null && !p.hasPermission("bau.team")) { p.sendMessage(BauSystem.PREFIX + "§cDu bist kein Mitglied dieser Welt"); return; } diff --git a/src/de/warking/bausystem/commands/CommandNV.java b/src/de/warking/bausystem/commands/CommandNV.java new file mode 100644 index 0000000..17f3685 --- /dev/null +++ b/src/de/warking/bausystem/commands/CommandNV.java @@ -0,0 +1,25 @@ +package de.warking.bausystem.commands; + +import de.pro_crafting.commandframework.Command; +import de.pro_crafting.commandframework.CommandArgs; +import de.warking.bausystem.BauSystem; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class CommandNV { + + @Command(name = "nv", aliases = "nightvision", inGameOnly = true) + public void onNightVision(CommandArgs args){ + Player p = args.getPlayer(); + for(PotionEffect effect : p.getActivePotionEffects()){ + if(effect.getType().equals(PotionEffectType.NIGHT_VISION)){ + p.sendMessage(BauSystem.PREFIX + "Nachtsicht deaktiviert"); + p.removePotionEffect(PotionEffectType.NIGHT_VISION); + return; + } + } + p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1000000, 255, false, false)); + p.sendMessage(BauSystem.PREFIX + "Nachtsicht aktiviert"); + } +} diff --git a/src/de/warking/bausystem/commands/CommandTeleport.java b/src/de/warking/bausystem/commands/CommandTeleport.java index 8e6b766..a039e04 100644 --- a/src/de/warking/bausystem/commands/CommandTeleport.java +++ b/src/de/warking/bausystem/commands/CommandTeleport.java @@ -72,7 +72,7 @@ public class CommandTeleport extends BukkitCommand { return false; } - if(worldOwner != p.getUniqueId()){ + if(!worldOwner.equals(p.getUniqueId())){ BauweltMember member = BauweltMember.getBauMember(worldOwner, p.getUniqueId()); if(member == null || !member.isTeleport()){ p.sendMessage(BauSystem.PREFIX + "§cDu darfst dich auf dieser Welt nicht teleportieren!"); @@ -80,11 +80,6 @@ public class CommandTeleport extends BukkitCommand { } } - /*if (!BauweltMember.getBauMember(p.getUniqueId(), target.getUniqueId()).isTeleport()){ - sender.sendMessage("Die Spieler sind nicht auf der selben Bauwelt."); - return false; - }*/ - p.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND); return true; } diff --git a/src/de/warking/bausystem/commands/CommandTrace.java b/src/de/warking/bausystem/commands/CommandTrace.java new file mode 100644 index 0000000..17a60a8 --- /dev/null +++ b/src/de/warking/bausystem/commands/CommandTrace.java @@ -0,0 +1,95 @@ +package de.warking.bausystem.commands; + +import de.pro_crafting.commandframework.Command; +import de.pro_crafting.commandframework.CommandArgs; +import de.warking.bausystem.BauSystem; +import de.warking.bausystem.world.TNTTracer; +import de.warking.hunjy.MySQL.BauweltMember; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public class CommandTrace { + + @Command(name = "trace", inGameOnly = true) + public void onTrace(CommandArgs args){ + Player p = args.getPlayer(); + p.sendMessage("§6/trace start §7- Startet die Aufnahme aller TNT-Positionen"); + p.sendMessage("§6/trace show §7- Zeigt alle TNT-Positionen"); + p.sendMessage("§6/trace hide §7- Versteckt die TNT-Positionen wieder"); + p.sendMessage("§6/trace stop §7- Bricht die Aufnahme ab"); + } + + @Command(name = "trace.start", inGameOnly = true) + public void onStart(CommandArgs args){ + Player p = args.getPlayer(); + if(checkPerm(p)){ + TNTTracer.newTracer(p.getWorld()); + p.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet"); + } + } + + @Command(name = "trace.stop", inGameOnly = true) + public void onStop(CommandArgs args){ + Player p = args.getPlayer(); + if(checkPerm(p)){ + TNTTracer t = TNTTracer.get(p.getWorld()); + if(t == null){ + p.sendMessage(BauSystem.PREFIX + "§cKein laufender TNT-Tracer"); + return; + } + t.end(); + p.sendMessage(BauSystem.PREFIX + "§aAufnahme abgebrochen"); + } + } + + @Command(name = "trace.show", inGameOnly = true) + public void onShow(CommandArgs args){ + Player p = args.getPlayer(); + if(checkPerm(p)){ + TNTTracer t = TNTTracer.get(p.getWorld()); + if(t == null){ + p.sendMessage(BauSystem.PREFIX + "§cKein laufender TNT-Tracer"); + return; + } + t.show(); + p.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen angezeigt"); + } + } + + @Command(name = "trace.hide", inGameOnly = true) + public void onHide(CommandArgs args){ + Player p = args.getPlayer(); + if(checkPerm(p)){ + TNTTracer t = TNTTracer.get(p.getWorld()); + if(t == null){ + p.sendMessage(BauSystem.PREFIX + "§cKein laufender TNT-Tracer"); + return; + } + t.hide(); + p.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen versteckt"); + } + } + + public boolean checkPerm(Player p){ + UUID id; + try{ + id = UUID.fromString(p.getWorld().getName()); + }catch(IllegalArgumentException E){ + p.sendMessage(BauSystem.PREFIX + "§cDu bist auf keiner Bauwelt"); + return false; + } + + if(p.getUniqueId().equals(id)){ + return true; + }else{ + BauweltMember member = BauweltMember.getBauMember(id, p.getUniqueId()); + if(member == null || member.isTestblock()) { + p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TNT-Tracer nutzen"); + return false; + }else{ + return true; + } + } + } +} diff --git a/src/de/warking/bausystem/world/LagDetectorRunnable.java b/src/de/warking/bausystem/world/LagDetectorRunnable.java index 403d9bc..6cd159f 100644 --- a/src/de/warking/bausystem/world/LagDetectorRunnable.java +++ b/src/de/warking/bausystem/world/LagDetectorRunnable.java @@ -20,6 +20,7 @@ public class LagDetectorRunnable implements Runnable { world.setThundering(false); world.setMonsterSpawnLimit(0); world.setAnimalSpawnLimit(0); + world.setGameRuleValue("announceAdvancements", "false"); UUID worldOwner; diff --git a/src/de/warking/bausystem/world/TNTTracer.java b/src/de/warking/bausystem/world/TNTTracer.java new file mode 100644 index 0000000..a5569a9 --- /dev/null +++ b/src/de/warking/bausystem/world/TNTTracer.java @@ -0,0 +1,136 @@ +package de.warking.bausystem.world; + +import de.warking.bausystem.BauSystem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.world.WorldUnloadEvent; +import org.bukkit.scheduler.BukkitTask; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class TNTTracer implements Listener, Runnable { + + private static final Map allTracer = new HashMap<>(); + + private final World world; + private final BukkitTask task; + private final Set locations; + private final Set tnts; + private boolean printed; + + private TNTTracer(World world){ + this.world = world; + this.locations = new HashSet<>(); + this.tnts = new HashSet<>(); + this.printed = false; + this.task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this, 1, 1); + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + allTracer.put(world, this); + } + + private void stop(){ + task.cancel(); + tnts.clear(); + HandlerList.unregisterAll(this); + } + + public void end(){ + stop(); + locations.clear(); + allTracer.remove(world); + } + + public void show(){ + stop(); + printed = true; + Set unsetLoc = new HashSet<>(); + for(Location l : locations){ + Block b = world.getBlockAt(l); + if(b.getType() != Material.AIR){ + unsetLoc.add(l); + continue; + } + b.setType(Material.STAINED_GLASS); + b.setData((byte) 1); + } + locations.removeAll(unsetLoc); + } + + public void hide(){ + end(); + if(!printed) + return; + for(Location l : locations){ + Block b = world.getBlockAt(l); + if(b.getType() != Material.STAINED_GLASS || b.getData() != 1) + continue; + b.setType(Material.AIR); + } + } + + @EventHandler + public void onExplode(EntityExplodeEvent e){ + if(e.getEntityType() != EntityType.PRIMED_TNT) + return; + + tnts.remove((TNTPrimed) e.getEntity()); + } + + @EventHandler + public void onSpawn(EntitySpawnEvent e){ + if(e.getEntityType() != EntityType.PRIMED_TNT) + return; + + if(e.getLocation().getWorld() != world) + return; + + if(tnts.size() > 150){ + for(Player p : Bukkit.getOnlinePlayers()){ + p.sendMessage(BauSystem.PREFIX + "§cEs können nicht mehr als 150 TNT verfolgt werden!"); + } + return; + } + + tnts.add((TNTPrimed) e.getEntity()); + } + + @EventHandler + public void onUnloadWorld(WorldUnloadEvent e){ + if(e.getWorld().equals(world)){ + end(); + } + } + + @Override + public void run() { + for(TNTPrimed tnt : tnts){ + locations.add(tnt.getLocation()); + } + } + + public static void newTracer(World w){ + if(allTracer.containsKey(w)){ + TNTTracer existing = allTracer.get(w); + existing.end(); + } + new TNTTracer(w); + } + + public static TNTTracer get(World w){ + return allTracer.get(w); + } +}