- handle regions on join
This commit is contained in:
parent
3bdca1cdb1
commit
2e8708f661
2 changed files with 22 additions and 10 deletions
|
@ -113,9 +113,9 @@ public class LCPlayer {
|
||||||
public boolean isOptionalRegionGameMode() {
|
public boolean isOptionalRegionGameMode() {
|
||||||
return getOptionalRegionGameMode() != null;
|
return getOptionalRegionGameMode() != null;
|
||||||
}
|
}
|
||||||
/*private boolean isOptionalRegionGameMode(final GameMode gm) {
|
public boolean isOptionalRegionGameMode(final GameMode gm) {
|
||||||
return gm.equals(getOptionalRegionGameMode());
|
return gm.equals(getOptionalRegionGameMode());
|
||||||
}*/
|
}
|
||||||
public boolean isOptionalRegionGameMode(final String region, final GameMode gm) {
|
public boolean isOptionalRegionGameMode(final String region, final GameMode gm) {
|
||||||
return gm.equals(getOptionalRegionGameMode(region));
|
return gm.equals(getOptionalRegionGameMode(region));
|
||||||
}
|
}
|
||||||
|
@ -337,9 +337,11 @@ public class LCPlayer {
|
||||||
public void setRegionCreativeAllowed(boolean rcreative, PlayerChangedAreaEvent changearea_event) {
|
public void setRegionCreativeAllowed(boolean rcreative, PlayerChangedAreaEvent changearea_event) {
|
||||||
Core.debug(getName()+": changed region: "+rcreative+": "+changearea_event.toString());
|
Core.debug(getName()+": changed region: "+rcreative+": "+changearea_event.toString());
|
||||||
|
|
||||||
PlayerMoveEvent event = changearea_event.getMoveEvent();
|
PlayerMoveEvent event = null;
|
||||||
GameMode CURRENT_GAMEMODE = event.getPlayer().getGameMode();
|
if (changearea_event != null)
|
||||||
GameMode DEFAULT_GAMEMODE = plugin.com.getDefaultGameMode(event.getTo().getWorld());
|
event = changearea_event.getMoveEvent();
|
||||||
|
GameMode CURRENT_GAMEMODE = getPlayer().getGameMode();
|
||||||
|
GameMode DEFAULT_GAMEMODE = plugin.com.getDefaultGameMode(event != null ? event.getTo().getWorld() : getPlayer().getWorld());
|
||||||
GameMode TEMPORARY_GAMEMODE = DEFAULT_GAMEMODE == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL; // the opposite
|
GameMode TEMPORARY_GAMEMODE = DEFAULT_GAMEMODE == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL; // the opposite
|
||||||
|
|
||||||
if (rcreative && CURRENT_GAMEMODE != TEMPORARY_GAMEMODE && !this.isRegionGameMode(TEMPORARY_GAMEMODE)) {
|
if (rcreative && CURRENT_GAMEMODE != TEMPORARY_GAMEMODE && !this.isRegionGameMode(TEMPORARY_GAMEMODE)) {
|
||||||
|
@ -349,16 +351,20 @@ public class LCPlayer {
|
||||||
// 3. and the player is not aware of that
|
// 3. and the player is not aware of that
|
||||||
// result: change him to that mode
|
// result: change him to that mode
|
||||||
setRegionGameMode(TEMPORARY_GAMEMODE); // have to be set, before setGameMode
|
setRegionGameMode(TEMPORARY_GAMEMODE); // have to be set, before setGameMode
|
||||||
if (!isOptionalRegionGameMode(changearea_event.getNewRegionHash(), CURRENT_GAMEMODE)) {
|
|
||||||
event.getPlayer().setGameMode(TEMPORARY_GAMEMODE);
|
boolean isOptional = changearea_event != null ?
|
||||||
|
isOptionalRegionGameMode(changearea_event.getNewRegionHash(), CURRENT_GAMEMODE) :
|
||||||
|
isOptionalRegionGameMode(CURRENT_GAMEMODE);
|
||||||
|
if (!isOptional) {
|
||||||
|
getPlayer().setGameMode(TEMPORARY_GAMEMODE);
|
||||||
}
|
}
|
||||||
} else if (!rcreative && event.getPlayer().getGameMode() == TEMPORARY_GAMEMODE && !isPermanentGameMode(TEMPORARY_GAMEMODE)) {
|
} else if (!rcreative && getPlayer().getGameMode() == TEMPORARY_GAMEMODE && !isPermanentGameMode(TEMPORARY_GAMEMODE)) {
|
||||||
Core.debug(getName()+": leaving creative area");
|
Core.debug(getName()+": leaving creative area");
|
||||||
// 1. the region doesn't allow "the other gamemode"
|
// 1. the region doesn't allow "the other gamemode"
|
||||||
// 2. but the player is in that mode
|
// 2. but the player is in that mode
|
||||||
// 3. and the player isn't global (permanent) in that mode
|
// 3. and the player isn't global (permanent) in that mode
|
||||||
// result: change him back to default mode
|
// result: change him back to default mode
|
||||||
if (CURRENT_GAMEMODE == GameMode.CREATIVE && getFloatingHeight() > plugin.config.getMaximumFloatingHeight()) {
|
if (event != null && CURRENT_GAMEMODE == GameMode.CREATIVE && getFloatingHeight() > plugin.config.getMaximumFloatingHeight()) {
|
||||||
// but not if he is too high
|
// but not if he is too high
|
||||||
this.sendTimeoutMessage(L("blocked.survival_flying"));
|
this.sendTimeoutMessage(L("blocked.survival_flying"));
|
||||||
|
|
||||||
|
@ -369,7 +375,7 @@ public class LCPlayer {
|
||||||
event.setTo(newloc);
|
event.setTo(newloc);
|
||||||
} else {
|
} else {
|
||||||
setRegionGameMode(null);
|
setRegionGameMode(null);
|
||||||
if (event.getTo().getWorld() == event.getFrom().getWorld()) {
|
if (event != null && event.getTo().getWorld() == event.getFrom().getWorld()) {
|
||||||
// do not enforce the game mode change, on world teleport, as multiverse may cancel the event afterwards
|
// do not enforce the game mode change, on world teleport, as multiverse may cancel the event afterwards
|
||||||
// the world-change game-mode change is done by multiworld
|
// the world-change game-mode change is done by multiworld
|
||||||
event.getPlayer().setGameMode(DEFAULT_GAMEMODE);
|
event.getPlayer().setGameMode(DEFAULT_GAMEMODE);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||||
|
@ -94,6 +95,11 @@ public class RegionListener implements Listener {
|
||||||
Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getNewRegionSet().allows(Flags.CREATIVE, event.getPlayer()), event);
|
Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getNewRegionSet().allows(Flags.CREATIVE, event.getPlayer()), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLogin(PlayerJoinEvent event) {
|
||||||
|
Players.get(event.getPlayer()).setRegionCreativeAllowed(rm.getRegionSet(event.getPlayer().getLocation()).allows(Flags.CREATIVE, event.getPlayer()), null);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPistonExtend(BlockPistonExtendEvent event) {
|
public void onPistonExtend(BlockPistonExtendEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
|
|
Loading…
Reference in a new issue