Mid commit on adding portal prevention
This commit is contained in:
parent
18a57bf975
commit
74726b44ab
|
@ -12,6 +12,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
|||
import com.onarandombox.MultiverseCore.configuration.ConfigPropertyFactory;
|
||||
import com.onarandombox.MultiverseCore.configuration.MVActiveConfigProperty;
|
||||
import com.onarandombox.MultiverseCore.configuration.MVConfigProperty;
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
|
@ -156,6 +157,8 @@ public class MVWorld implements MultiverseWorld {
|
|||
this.propertyList.put("adjustspawn", fac.getNewProperty("adjustspawn", true,
|
||||
"Sorry, 'adjustspawn' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE
|
||||
+ "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("portalform", fac.getNewProperty("portalform", AllowedPortalType.ALL,
|
||||
"Allow portal forming must be NONE, ALL, NETHER or END."));
|
||||
if (!fixSpawn) {
|
||||
this.setAdjustSpawn(false);
|
||||
}
|
||||
|
@ -1159,6 +1162,22 @@ public class MVWorld implements MultiverseWorld {
|
|||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void allowPortalMaking(AllowedPortalType type) {
|
||||
this.setKnownProperty("bedrespawn", type.toString(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public AllowedPortalType getAllowedPortals() {
|
||||
return this.getKnownProperty("portalform", AllowedPortalType.class).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the active time-property to set the "actual" property.
|
||||
* @return True if the property was successfully set.
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
|||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
|
||||
import com.onarandombox.MultiverseCore.utils.*;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -153,6 +154,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||
private MVEntityListener entityListener = new MVEntityListener(this);
|
||||
private MVPluginListener pluginListener = new MVPluginListener(this);
|
||||
private MVWeatherListener weatherListener = new MVWeatherListener(this);
|
||||
private MVPortalListener portalListener = new MVPortalListener(this);
|
||||
|
||||
//public UpdateChecker updateCheck;
|
||||
|
||||
|
@ -324,6 +326,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||
pm.registerEvents(this.entityListener, this);
|
||||
pm.registerEvents(this.pluginListener, this);
|
||||
pm.registerEvents(this.weatherListener, this);
|
||||
pm.registerEvents(this.portalListener, this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.configuration.MVConfigProperty;
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -573,4 +574,18 @@ public interface MultiverseWorld {
|
|||
* @return The Type of this world.
|
||||
*/
|
||||
WorldType getWorldType();
|
||||
|
||||
/**
|
||||
* Sets The types of portals that are allowed in this world.
|
||||
*
|
||||
* @param type The type of portals allowed in this world.
|
||||
*/
|
||||
void allowPortalMaking(AllowedPortalType type);
|
||||
|
||||
/**
|
||||
* Gets which type(s) of portals are allowed to be constructed in this world.
|
||||
*
|
||||
* @return The type of portals that are allowed.
|
||||
*/
|
||||
AllowedPortalType getAllowedPortals();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
|
@ -233,9 +234,9 @@ public class ConfigPropertyFactory {
|
|||
return new GameModeConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
// GameMode
|
||||
// Location
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
* Constructs a new LocationConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
|
@ -273,6 +274,19 @@ public class ConfigPropertyFactory {
|
|||
return new LocationConfigProperty(this.section, name, defaultValue, node, help, method);
|
||||
}
|
||||
|
||||
// GameMode
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public PortalTypeConfigProperty getNewProperty(String name, AllowedPortalType defaultValue, String help) {
|
||||
return new PortalTypeConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ActiveStringConfigProperty
|
||||
*
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link org.bukkit.GameMode} config-property.
|
||||
*/
|
||||
public class PortalTypeConfigProperty implements MVConfigProperty<AllowedPortalType> {
|
||||
private String name;
|
||||
private AllowedPortalType value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
|
||||
public PortalTypeConfigProperty(ConfigurationSection section, String name, AllowedPortalType defaultValue, String help) {
|
||||
this(section, name, defaultValue, name, help);
|
||||
}
|
||||
|
||||
public PortalTypeConfigProperty(ConfigurationSection section, String name, AllowedPortalType defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.value = defaultValue;
|
||||
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public AllowedPortalType getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(AllowedPortalType value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
this.section.set(configNode, this.value.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean parseValue(String value) {
|
||||
try {
|
||||
return this.setValue(AllowedPortalType.valueOf(value.toUpperCase()));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getConfigNode() {
|
||||
return this.configNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
import org.bukkit.PortalType;
|
||||
|
||||
/**
|
||||
* Custom enum that adds all/none for allowing
|
||||
*/
|
||||
public enum AllowedPortalType {
|
||||
/**
|
||||
* No portals are allowed.
|
||||
*/
|
||||
NONE(PortalType.CUSTOM),
|
||||
/**
|
||||
* All portal types are allowed.
|
||||
*/
|
||||
ALL(PortalType.CUSTOM),
|
||||
/**
|
||||
* Only Nether style portals are allowed.
|
||||
*/
|
||||
NETHER(PortalType.NETHER),
|
||||
/**
|
||||
* Only Ender style portals are allowed.
|
||||
*/
|
||||
END(PortalType.ENDER);
|
||||
|
||||
private PortalType type;
|
||||
|
||||
AllowedPortalType(PortalType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text.
|
||||
* @return The text.
|
||||
*/
|
||||
public PortalType getActualPortalType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
|
@ -308,7 +308,7 @@ public class MVPlayerListener implements Listener {
|
|||
public void run() {
|
||||
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
||||
if (player.getWorld() == world.getCBWorld()) {
|
||||
MultiverseCore.staticLog(Level.FINE, "Handeling gamemode for player: " + player.getName() + ", " + world.getGameMode().toString());
|
||||
MultiverseCore.staticLog(Level.FINE, "Handling gamemode for player: " + player.getName() + ", " + world.getGameMode().toString());
|
||||
MultiverseCore.staticLog(Level.FINE, "PWorld: " + player.getWorld());
|
||||
MultiverseCore.staticLog(Level.FINE, "AWorld: " + world);
|
||||
player.setGameMode(world.getGameMode());
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.PortalType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityCreatePortalEvent;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
|
||||
/**
|
||||
* A custom listener for portal related events.
|
||||
*/
|
||||
public class MVPortalListener implements Listener {
|
||||
|
||||
private MultiverseCore plugin;
|
||||
|
||||
public MVPortalListener(MultiverseCore core) {
|
||||
this.plugin = core;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when an entity creates a portal.
|
||||
*
|
||||
* @param event The event where an entity created a portal.
|
||||
*/
|
||||
@EventHandler
|
||||
public void entityPortalCreate(EntityCreatePortalEvent event) {
|
||||
if (event.isCancelled() || event.getBlocks().size() == 0) {
|
||||
return;
|
||||
}
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
|
||||
event.setCancelled(this.cancelPortalEvent(world, event.getPortalType()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when a portal is created as the result of another world being linked.
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void portalForm(PortalCreateEvent event) {
|
||||
if (event.isCancelled() || event.getBlocks().size() == 0) {
|
||||
return;
|
||||
}
|
||||
// There's no type attribute (as of 1.1-R1), so we have to iterate.
|
||||
for (Block b : event.getBlocks()) {
|
||||
if (b.getType() == Material.PORTAL) {
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(b.getWorld());
|
||||
event.setCancelled(this.cancelPortalEvent(world, PortalType.NETHER));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If We're here, then the Portal was an Ender type:
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
|
||||
event.setCancelled(this.cancelPortalEvent(world, PortalType.ENDER));
|
||||
}
|
||||
|
||||
private boolean cancelPortalEvent(MultiverseWorld world, PortalType type) {
|
||||
if (world.getAllowedPortals() == AllowedPortalType.NONE) {
|
||||
return true;
|
||||
} else if (world.getAllowedPortals() != AllowedPortalType.ALL) {
|
||||
if (type != world.getAllowedPortals().getActualPortalType()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue