Ticket #146 (possible fix)

- MultiWorld World GameMode support
 - EventPriority onGameModeChange fix
This commit is contained in:
Jascha Starke 2013-09-14 13:53:15 +02:00
parent 7385478e13
commit db97f869d7
6 changed files with 43 additions and 6 deletions

View file

@ -92,6 +92,12 @@
<artifactId>Multiverse-Core</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/bukkit-plugins/multiworld-v-2-0/ -->
<groupId>multiworld</groupId>
<artifactId>multiworld</artifactId>
<version>4.6.6</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/xauth/ -->
<groupId>com.cypherx</groupId>

View file

@ -110,10 +110,10 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
/**
* Don't default Plugin-debug to this mod. Because it is too spammy.
* /
*/
public boolean isDebug() {
return debug;
}*/
}
private class CleanUp extends BukkitRunnable {
public long maxTime = 0;

View file

@ -6,6 +6,7 @@ import de.jaschastarke.hooking.BooleanHooker;
import de.jaschastarke.hooking.GetHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.MultiWorldHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.xAuthHooks;
@ -34,6 +35,8 @@ public final class Hooks {
}
if (isPluginEnabled("Multiverse-Core")) {
new MultiVerseHooks(plugin);
} else if (isPluginEnabled("MultiWorld")) {
new MultiWorldHooks(plugin);
}
InventoryIncompatible.register(new GetHooker.Check<String>() {

View file

@ -0,0 +1,28 @@
package de.jaschastarke.minecraft.limitedcreative.hooks;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.World;
import de.jaschastarke.minecraft.limitedcreative.Hooks;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
import multiworld.MultiWorldPlugin;
import multiworld.api.MultiWorldAPI;
public class MultiWorldHooks {
public MultiWorldHooks(final LimitedCreative plugin) {
Hooks.DefaultWorldGameMode.register(new WorldTypeHooker.Check() {
@Override
public GameMode get(World world) {
boolean creative = getMWApi().isCreativeWorld(world.getName());
GameMode gm = creative ? GameMode.CREATIVE : GameMode.SURVIVAL;
plugin.getLog().debug("MultiWorld: "+world.getName()+": game mode: "+gm);
return gm;
}
});
}
private static MultiWorldAPI getMWApi() {
return ((MultiWorldPlugin) Bukkit.getServer().getPluginManager().getPlugin("MultiWorld")).getApi();
}
}

View file

@ -19,6 +19,7 @@ package de.jaschastarke.minecraft.limitedcreative.inventories;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
@ -32,7 +33,7 @@ public class PlayerListener implements Listener {
this.mod = mod;
}
@EventHandler
@EventHandler(priority=EventPriority.LOW, ignoreCancelled = true)
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
boolean isLoggedIn = Hooks.IsLoggedIn.test(event.getPlayer());
if (mod.isDebug()) {

View file

@ -8,7 +8,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
@ -80,14 +79,14 @@ public class PlayerListener extends Listener {
return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL);
}
@EventHandler(priority = EventPriority.LOW)
@EventHandler(ignoreCancelled = true)
public void onGameModeChange(PlayerGameModeChangeEvent event) {
Player player = event.getPlayer();
PlayerMeta pmeta = new PlayerMeta(player);
GameMode gm = event.getNewGameMode();
if (mod.isDebug())
mod.getLog().debug(player.getName() + " is changing to GameMode " + gm);;
mod.getLog().debug(player.getName() + " is changing to GameMode " + gm);
if (Hooks.IsLoggedIn.test(player)) { // if authme is changing GameMode before going to teleport, this should be remembered
if (pmeta.isActiveRegionGameMode()) { // change to the other gamemode as the area defines
if (!pmeta.isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows