From 4cf65fefa10035c0c32e601768cf4b6d97840b17 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 21 Dec 2016 19:02:48 -0500 Subject: [PATCH] Fully disabled Creative in World --- .../components/hotfix/HotfixComponent.java | 2 ++ .../hotfix/hotfixes/CreativeKillLoop.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/buttondevteam/alipresents/components/hotfix/hotfixes/CreativeKillLoop.java diff --git a/src/buttondevteam/alipresents/components/hotfix/HotfixComponent.java b/src/buttondevteam/alipresents/components/hotfix/HotfixComponent.java index 45e6a2a..abd2393 100644 --- a/src/buttondevteam/alipresents/components/hotfix/HotfixComponent.java +++ b/src/buttondevteam/alipresents/components/hotfix/HotfixComponent.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.Essentials; import buttondevteam.alipresents.architecture.Component; import buttondevteam.alipresents.components.hotfix.hotfixes.CowSpawnLoop; +import buttondevteam.alipresents.components.hotfix.hotfixes.CreativeKillLoop; import buttondevteam.alipresents.components.hotfix.hotfixes.GrassBreakListener; import buttondevteam.alipresents.components.hotfix.hotfixes.MobKillListener; import buttondevteam.alipresents.components.hotfix.hotfixes.NetherDisableListener; @@ -19,6 +20,7 @@ public class HotfixComponent extends Component { registerListener(plugin, new CowSpawnLoop(plugin)); registerListener(plugin, new MobKillListener((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"))); registerListener(plugin, new GrassBreakListener()); + registerListener(plugin, new CreativeKillLoop(plugin)); } diff --git a/src/buttondevteam/alipresents/components/hotfix/hotfixes/CreativeKillLoop.java b/src/buttondevteam/alipresents/components/hotfix/hotfixes/CreativeKillLoop.java new file mode 100644 index 0000000..d127982 --- /dev/null +++ b/src/buttondevteam/alipresents/components/hotfix/hotfixes/CreativeKillLoop.java @@ -0,0 +1,28 @@ +package buttondevteam.alipresents.components.hotfix.hotfixes; + +import org.bukkit.GameMode; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +public class CreativeKillLoop extends BukkitRunnable implements Listener { + private Server server; + + public CreativeKillLoop(JavaPlugin plugin){ + this.server = plugin.getServer(); + this.runTaskTimer(plugin, 40, 40); + } + + @Override + public void run() { + for (Player player : server.getOnlinePlayers()){ + if(player.getGameMode() != GameMode.SURVIVAL && player.getWorld().getName() == "World" && player.isOp() == false){ + player.sendMessage("[Hotfix] Every Gamemode other than survival is disabled in the new world!"); + player.setGameMode(GameMode.SURVIVAL); + } + } + } + +}