mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2024-12-02 13:23:21 +01:00
Fixed #18
This commit is contained in:
parent
b5faa1d836
commit
3a5ebb7346
@ -1,6 +1,12 @@
|
||||
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.GameMode;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
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.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 {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
World from = e.getFrom().getWorld();
|
||||
World to = e.getTo().getWorld();
|
||||
WorldPlayer wp = new WorldPlayer(p);
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
World from = e.getFrom().getWorld();
|
||||
World to = e.getTo().getWorld();
|
||||
WorldPlayer wp = new WorldPlayer(p);
|
||||
|
||||
if (from != to)
|
||||
SystemWorld.tryUnloadLater(from);
|
||||
if (from != to)
|
||||
SystemWorld.tryUnloadLater(from);
|
||||
|
||||
if (e.getCause() == TeleportCause.SPECTATE) {
|
||||
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());
|
||||
} 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);
|
||||
if (e.getCause() == TeleportCause.SPECTATE) {
|
||||
if (from != to && WorldConfig.exists(to.getName())) {
|
||||
if (!p.hasPermission("ws.tp.toother")) {
|
||||
e.setCancelled(true);
|
||||
p.sendMessage(MessageConfig.getNoPermission());
|
||||
return;
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
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());
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user