This commit is contained in:
Butzlabben 2019-02-25 15:14:34 +01:00
parent b5faa1d836
commit 3a5ebb7346

View File

@ -1,6 +1,12 @@
package de.butzlabben.world.listener; package de.butzlabben.world.listener;
import de.butzlabben.world.config.MessageConfig;
import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.config.WorldConfig;
import de.butzlabben.world.wrapper.SystemWorld;
import de.butzlabben.world.wrapper.WorldPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -10,123 +16,132 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import de.butzlabben.world.config.MessageConfig;
import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.config.WorldConfig;
import de.butzlabben.world.wrapper.SystemWorld;
import de.butzlabben.world.wrapper.WorldPlayer;
public class CommandListener implements Listener { public class CommandListener implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onTeleport(PlayerTeleportEvent e) { public void onTeleport(PlayerTeleportEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
World from = e.getFrom().getWorld(); World from = e.getFrom().getWorld();
World to = e.getTo().getWorld(); World to = e.getTo().getWorld();
WorldPlayer wp = new WorldPlayer(p); WorldPlayer wp = new WorldPlayer(p);
if (from != to) if (from != to)
SystemWorld.tryUnloadLater(from); SystemWorld.tryUnloadLater(from);
if (e.getCause() == TeleportCause.SPECTATE) { if (e.getCause() == TeleportCause.SPECTATE) {
if (from != to && WorldConfig.exists(to.getName())) { if (from != to && WorldConfig.exists(to.getName())) {
if (!p.hasPermission("ws.tp.toother")) { if (!p.hasPermission("ws.tp.toother")) {
e.setCancelled(true); e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission()); p.sendMessage(MessageConfig.getNoPermission());
return; return;
} }
}
if (!wp.isOnSystemWorld() || wp.isOwnerofWorld() || wp.canTeleport() || p.hasPermission("ws.tp.toother"))
return;
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
} else if (e.getCause() == TeleportCause.COMMAND) {
if (from != to && WorldConfig.exists(to.getName())) {
if (!p.hasPermission("ws.tp.toother")) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
return;
}
}
if (!wp.isOnSystemWorld() || wp.isOwnerofWorld() || wp.canTeleport() || p.hasPermission("ws.tp.toother"))
return;
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onCmd(PlayerCommandPreprocessEvent e) {
String cmd = e.getMessage().toLowerCase();
Player p = e.getPlayer();
WorldPlayer wp = new WorldPlayer(p);
if (!wp.isOnSystemWorld())
return;
if (cmd.startsWith("/gamemode") || cmd.startsWith("/gm")) {
if (!wp.isOnSystemWorld())
return;
if (p.hasPermission("ws.gamemode"))
return;
if (PluginConfig.isSurvival()) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
return;
}
if (!wp.canChangeGamemode() && !wp.isOwnerofWorld()) {
p.sendMessage(MessageConfig.getNoPermission());
e.setCancelled(true);
} }
} else if (cmd.startsWith("/tp") || cmd.startsWith("/teleport")) {
String[] args = e.getMessage().split(" ");
if (args.length == 2) {
if (p.hasPermission("ws.tp.toother"))
return;
if (PluginConfig.isSurvival()) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
return;
}
Player a = Bukkit.getPlayer(args[1]);
if (a == null)
return;
if (p.getWorld() != a.getWorld()) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
return;
}
if (wp.isOwnerofWorld())
return;
if (!wp.canTeleport()) {
p.sendMessage(MessageConfig.getNoPermission());
e.setCancelled(true);
}
} else if (args.length == 3) {
if (!p.hasPermission("ws.tp.other")) {
p.sendMessage(MessageConfig.getNoPermission());
e.setCancelled(true);
}
} else if (args.length == 4) { if (!wp.isOnSystemWorld() || wp.isOwnerofWorld() || wp.canTeleport() || p.hasPermission("ws.tp.toother"))
if (p.hasPermission("ws.tp.toother")) return;
return;
if (PluginConfig.isSurvival()) { e.setCancelled(true);
e.setCancelled(true); p.sendMessage(MessageConfig.getNoPermission());
p.sendMessage(MessageConfig.getNoPermission()); } else if (e.getCause() == TeleportCause.COMMAND) {
return; if (from != to && WorldConfig.exists(to.getName())) {
} if (!p.hasPermission("ws.tp.toother")) {
if (wp.isOwnerofWorld()) e.setCancelled(true);
return; p.sendMessage(MessageConfig.getNoPermission());
if (!wp.canTeleport()) { return;
p.sendMessage(MessageConfig.getNoPermission());
e.setCancelled(true);
} }
} }
}
} if (!wp.isOnSystemWorld() || wp.isOwnerofWorld() || wp.canTeleport() || p.hasPermission("ws.tp.toother"))
return;
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
}
// Fix for #18
if (from != to || WorldConfig.exists(from.getName())) {
GameMode gameMode = PluginConfig.getSpawnGamemode();
if (WorldConfig.exists(to.getName())) {
if (PluginConfig.isSurvival()) {
gameMode = GameMode.SURVIVAL;
} else {
gameMode = GameMode.CREATIVE;
}
}
p.setGameMode(gameMode);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onCmd(PlayerCommandPreprocessEvent e) {
String cmd = e.getMessage().toLowerCase();
Player p = e.getPlayer();
WorldPlayer wp = new WorldPlayer(p);
if (!wp.isOnSystemWorld())
return;
if (cmd.startsWith("/gamemode") || cmd.startsWith("/gm")) {
if (!wp.isOnSystemWorld())
return;
if (p.hasPermission("ws.gamemode"))
return;
if (PluginConfig.isSurvival()) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
return;
}
if (!wp.canChangeGamemode() && !wp.isOwnerofWorld()) {
p.sendMessage(MessageConfig.getNoPermission());
e.setCancelled(true);
}
} else if (cmd.startsWith("/tp") || cmd.startsWith("/teleport")) {
String[] args = e.getMessage().split(" ");
if (args.length == 2) {
if (p.hasPermission("ws.tp.toother"))
return;
if (PluginConfig.isSurvival()) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
return;
}
Player a = Bukkit.getPlayer(args[1]);
if (a == null)
return;
if (p.getWorld() != a.getWorld()) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
return;
}
if (wp.isOwnerofWorld())
return;
if (!wp.canTeleport()) {
p.sendMessage(MessageConfig.getNoPermission());
e.setCancelled(true);
}
} else if (args.length == 3) {
if (!p.hasPermission("ws.tp.other")) {
p.sendMessage(MessageConfig.getNoPermission());
e.setCancelled(true);
}
} else if (args.length == 4) {
if (p.hasPermission("ws.tp.toother"))
return;
if (PluginConfig.isSurvival()) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
return;
}
if (wp.isOwnerofWorld())
return;
if (!wp.canTeleport()) {
p.sendMessage(MessageConfig.getNoPermission());
e.setCancelled(true);
}
}
}
}
} }