Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
355e824408 | ||
|
|
3e7841afc9 | ||
|
|
1427671a8c | ||
|
|
a15317e21d | ||
|
|
b10a37f232 | ||
|
|
144de09423 | ||
|
|
a60e4e06e1 | ||
|
|
9eccf93b66 | ||
|
|
220f6a31de | ||
|
|
8cb4f22467 | ||
|
|
a2a2594f5a | ||
|
|
87df407743 | ||
|
|
cf007f091a | ||
|
|
680c35e0dc | ||
|
|
1a385c21d7 | ||
|
|
cced74d4b0 | ||
|
|
1db555581b | ||
|
|
63e0c028d9 | ||
|
|
ee82dc213f | ||
|
|
d2c09b9d33 | ||
|
|
21a3eeacc8 | ||
|
|
48768b5d6c | ||
|
|
96294c092c | ||
|
|
9a3fde2f13 | ||
|
|
6520a31938 | ||
|
|
f1779c9e68 | ||
|
|
9cc35d7b12 | ||
|
|
02347e05d8 | ||
|
|
a4196a901a | ||
|
|
9b2dd0d6c9 | ||
|
|
0efb28be19 | ||
|
|
5d9941d073 | ||
|
|
82cfbaba4e | ||
|
|
9868c66cdb | ||
|
|
3a32857683 | ||
|
|
d7a3e1839e | ||
|
|
1496d940bf | ||
|
|
bd57ec19d2 | ||
|
|
da54f9769b | ||
|
|
2e4b814d6d | ||
|
|
3f93fb3648 | ||
|
|
176e729a87 | ||
|
|
62f79e7592 | ||
|
|
f60f770b98 | ||
|
|
3c434d18e3 | ||
|
|
c9b52c81a6 | ||
|
|
5be6ea2766 | ||
|
|
98f5e1e4ee | ||
|
|
de6fc6481e | ||
|
|
dcc6b828a8 | ||
|
|
7da91f7875 | ||
|
|
d84f930a54 | ||
|
|
bdd5e8bd91 | ||
|
|
d1280a9031 | ||
|
|
08b8f01c44 | ||
|
|
fd227960b9 | ||
|
|
0efc0b965b | ||
|
|
bbe134bd1a | ||
|
|
91f7debb08 | ||
|
|
871a601e37 | ||
|
|
bd7ad20b7b | ||
|
|
873d878252 | ||
|
|
8c63cac4c5 | ||
|
|
283913010f | ||
|
|
109582335b | ||
|
|
3f09fbd710 | ||
|
|
ccb96ead10 | ||
|
|
5c48899d92 | ||
|
|
5f5d7084fa | ||
|
|
7b9c26d40a | ||
|
|
0c96da48f9 | ||
|
|
fbbe031b2c | ||
|
|
868ac57a4a | ||
|
|
7c21a114db | ||
|
|
e7573d3bd7 | ||
|
|
772d5a222d | ||
|
|
9eaca3e093 |
No files matched your search
@@ -76,7 +76,10 @@
|
||||
<module name="UnusedImports">
|
||||
<property name="processJavadoc" value="true"/>
|
||||
</module>
|
||||
<module name="MethodLength"/>
|
||||
<module name="MethodLength">
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="countEmpty" value="false"/>
|
||||
</module>
|
||||
<module name="ParameterNumber"/>
|
||||
<module name="EmptyForIteratorPad"/>
|
||||
<module name="MethodParamPad"/>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.onarandombox.multiversecore</groupId>
|
||||
<artifactId>Multiverse-Core</artifactId>
|
||||
<version>2.3</version>
|
||||
<version>2.5</version>
|
||||
<name>Multiverse-Core</name>
|
||||
<description>World Management Plugin</description>
|
||||
<properties>
|
||||
@@ -180,23 +180,25 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.1-R3</version>
|
||||
<version>1.2.5-R1.0</version>
|
||||
<!-- If you want the lates, use this -->
|
||||
<!-- <version>LATEST</version> -->
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Bukkit Dependency -->
|
||||
<!-- Start of Spout -->
|
||||
<!-- Start of Spout (disabled because we aren't using it)
|
||||
<dependency>
|
||||
<groupId>org.getspout</groupId>
|
||||
<artifactId>spoutpluginapi</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- End of Spout -->
|
||||
End of Spout -->
|
||||
<!-- SerializationConfig Dependency -->
|
||||
<dependency>
|
||||
<groupId>me.main__.util</groupId>
|
||||
<artifactId>SerializationConfig</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>1.6b</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -205,7 +207,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fernferret.allpay</groupId>
|
||||
<artifactId>AllPay</artifactId>
|
||||
<version>8</version>
|
||||
<version>10</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -214,7 +216,7 @@
|
||||
<dependency>
|
||||
<groupId>com.pneumaticraft.commandhandler</groupId>
|
||||
<artifactId>CommandHandler</artifactId>
|
||||
<version>6</version>
|
||||
<version>7</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -18,7 +18,36 @@ import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.commands.*;
|
||||
import com.onarandombox.MultiverseCore.commands.AnchorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CheckCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ConfigCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ConfirmCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CoordCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CreateCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.DebugCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.DeleteCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GeneratorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.HelpCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ImportCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.InfoCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ListCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.LoadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyAddCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyClearCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyRemoveCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifySetCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.PurgeCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.RegenCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ReloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.RemoveCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.SetSpawnCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.SpawnCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.UnloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.VersionCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.WhoCommand;
|
||||
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.BedDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.CannonDestination;
|
||||
@@ -27,21 +56,29 @@ import com.onarandombox.MultiverseCore.destination.ExactDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.PlayerDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
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.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.DebugLog;
|
||||
import com.onarandombox.MultiverseCore.utils.MVMessaging;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -52,7 +89,9 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@@ -63,14 +102,14 @@ import java.util.logging.Logger;
|
||||
* The implementation of the Multiverse-{@link Core}.
|
||||
*/
|
||||
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private static final int PROTOCOL = 14;
|
||||
private static final int PROTOCOL = 15;
|
||||
// TODO: Investigate if this one is really needed to be static.
|
||||
// Doubt it. -- FernFerret
|
||||
private static Map<String, String> teleportQueue = new HashMap<String, String>();
|
||||
|
||||
private AnchorManager anchorManager = new AnchorManager(this);
|
||||
// TODO please let's make this non-static
|
||||
private static MultiverseCoreConfiguration config;
|
||||
private MultiverseCoreConfiguration config;
|
||||
|
||||
/**
|
||||
* This method is used to find out who is teleporting a player.
|
||||
@@ -159,7 +198,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private AllPay banker;
|
||||
private int pluginCount;
|
||||
private DestinationFactory destFactory;
|
||||
private SpoutInterface spoutInterface = null;
|
||||
//private SpoutInterface spoutInterface = null;
|
||||
private MultiverseMessaging messaging;
|
||||
private BlockSafety blockSafety;
|
||||
private LocationManipulation locationManipulation;
|
||||
@@ -171,10 +210,14 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
public void onLoad() {
|
||||
// Register our config
|
||||
SerializationConfig.registerAll(MultiverseCoreConfiguration.class);
|
||||
// Register our world
|
||||
SerializationConfig.registerAll(MVWorld.class);
|
||||
// Create our DataFolder
|
||||
getDataFolder().mkdirs();
|
||||
// Setup our Debug Log
|
||||
debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log");
|
||||
debugLog.setStandardLogger(LOGGER);
|
||||
SerializationConfig.initLogging(debugLog);
|
||||
// Setup our BlockSafety
|
||||
this.blockSafety = new SimpleBlockSafety(this);
|
||||
// Setup our LocationManipulation
|
||||
@@ -253,11 +296,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// A test that had no worlds loaded was being run. This should never happen in production
|
||||
}
|
||||
this.saveMVConfig();
|
||||
/*
|
||||
// Check to see if spout was already loaded (most likely):
|
||||
if (this.getServer().getPluginManager().getPlugin("Spout") != null) {
|
||||
this.setSpout();
|
||||
this.log(Level.INFO, "Spout integration enabled.");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void initializeDestinationFactory() {
|
||||
@@ -295,7 +340,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.multiverseConfig.setDefaults(coreDefaults);
|
||||
this.multiverseConfig.options().copyDefaults(false);
|
||||
this.multiverseConfig.options().copyHeader(true);
|
||||
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
|
||||
|
||||
MultiverseCoreConfiguration wantedConfig = null;
|
||||
try {
|
||||
@@ -305,6 +349,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
} finally {
|
||||
config = ((wantedConfig == null) ? new MultiverseCoreConfiguration() : wantedConfig);
|
||||
}
|
||||
this.migrateWorldConfig();
|
||||
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
|
||||
|
||||
this.messaging.setCooldown(config.getMessageCooldown());
|
||||
|
||||
@@ -369,6 +415,216 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate the worlds.yml to SerializationConfig.
|
||||
*/
|
||||
private void migrateWorldConfig() {
|
||||
FileConfiguration wconf = YamlConfiguration
|
||||
.loadConfiguration(new File(getDataFolder(), "worlds.yml"));
|
||||
|
||||
if (!wconf.isConfigurationSection("worlds")) {// empty config
|
||||
this.log(Level.FINE, "No worlds to migrate!");
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> values = wconf.getConfigurationSection("worlds").getValues(false);
|
||||
|
||||
boolean wasChanged = false;
|
||||
Map<String, Object> newValues = new LinkedHashMap<String, Object>(values.size());
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
if (entry.getValue() instanceof MVWorld) {
|
||||
// fine
|
||||
newValues.put(entry.getKey(), entry.getValue());
|
||||
} else if (entry.getValue() instanceof ConfigurationSection) {
|
||||
this.log(Level.FINE, "Migrating: " + entry.getKey());
|
||||
// we have to migrate this
|
||||
MVWorld world = new MVWorld(Collections.EMPTY_MAP);
|
||||
ConfigurationSection section = (ConfigurationSection) entry.getValue();
|
||||
|
||||
// migrate animals and monsters
|
||||
if (section.isConfigurationSection("animals")) {
|
||||
ConfigurationSection animalSection = section.getConfigurationSection("animals");
|
||||
if (animalSection.contains("spawn")) {
|
||||
if (animalSection.isBoolean("spawn"))
|
||||
world.setAllowAnimalSpawn(animalSection.getBoolean("spawn"));
|
||||
else
|
||||
world.setAllowAnimalSpawn(Boolean.parseBoolean(animalSection.getString("spawn")));
|
||||
}
|
||||
if (animalSection.isList("exceptions")) {
|
||||
world.getAnimalList().clear();
|
||||
world.getAnimalList().addAll(animalSection.getStringList("exceptions"));
|
||||
}
|
||||
}
|
||||
if (section.isConfigurationSection("monsters")) {
|
||||
ConfigurationSection monsterSection = section.getConfigurationSection("monsters");
|
||||
if (monsterSection.contains("spawn")) {
|
||||
if (monsterSection.isBoolean("spawn"))
|
||||
world.setAllowMonsterSpawn(monsterSection.getBoolean("spawn"));
|
||||
else
|
||||
world.setAllowMonsterSpawn(Boolean.parseBoolean(monsterSection.getString("spawn")));
|
||||
}
|
||||
if (monsterSection.isList("exceptions")) {
|
||||
world.getMonsterList().clear();
|
||||
world.getMonsterList().addAll(monsterSection.getStringList("exceptions"));
|
||||
}
|
||||
}
|
||||
|
||||
// migrate entryfee
|
||||
if (section.isConfigurationSection("entryfee")) {
|
||||
ConfigurationSection feeSection = section.getConfigurationSection("entryfee");
|
||||
if (feeSection.isInt("currency"))
|
||||
world.setCurrency(feeSection.getInt("currency"));
|
||||
|
||||
if (feeSection.isDouble("amount"))
|
||||
world.setPrice(feeSection.getDouble("amount"));
|
||||
else if (feeSection.isInt("amount"))
|
||||
world.setPrice(feeSection.getInt("amount"));
|
||||
}
|
||||
|
||||
// migrate pvp
|
||||
if (section.isBoolean("pvp")) {
|
||||
world.setPVPMode(section.getBoolean("pvp"));
|
||||
}
|
||||
|
||||
// migrate alias
|
||||
if (section.isConfigurationSection("alias")) {
|
||||
ConfigurationSection aliasSection = section.getConfigurationSection("alias");
|
||||
if (aliasSection.isString("color"))
|
||||
world.setColor(aliasSection.getString("color"));
|
||||
if (aliasSection.isString("name"))
|
||||
world.setAlias(aliasSection.getString("name"));
|
||||
}
|
||||
|
||||
// migrate worldblacklist
|
||||
if (section.isList("worldblacklist")) {
|
||||
world.getWorldBlacklist().clear();
|
||||
world.getWorldBlacklist().addAll(section.getStringList("worldblacklist"));
|
||||
}
|
||||
|
||||
// migrate scale
|
||||
if (section.isDouble("scale")) {
|
||||
world.setScaling(section.getDouble("scale"));
|
||||
}
|
||||
|
||||
// migrate gamemode
|
||||
if (section.isString("gamemode")) {
|
||||
try {
|
||||
world.setPropertyValue("gamemode", section.getString("gamemode"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
}
|
||||
}
|
||||
|
||||
// migrate hunger
|
||||
if (section.isBoolean("hunger")) {
|
||||
world.setHunger(section.getBoolean("hunger"));
|
||||
}
|
||||
|
||||
// migrate hidden
|
||||
if (section.isBoolean("hidden")) {
|
||||
world.setHidden(section.getBoolean("hidden"));
|
||||
}
|
||||
|
||||
// migrate autoheal
|
||||
if (section.isBoolean("autoheal")) {
|
||||
world.setAutoHeal(section.getBoolean("autoheal"));
|
||||
}
|
||||
|
||||
// migrate portalform
|
||||
if (section.isString("portalform")) {
|
||||
try {
|
||||
world.setPropertyValue("portalform", section.getString("portalform"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
}
|
||||
}
|
||||
|
||||
// migrate environment
|
||||
if (section.isString("environment")) {
|
||||
try {
|
||||
world.setPropertyValue("environment", section.getString("environment"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
}
|
||||
}
|
||||
|
||||
// migrate generator
|
||||
if (section.isString("generator")) {
|
||||
world.setGenerator(section.getString("generator"));
|
||||
}
|
||||
|
||||
// migrate seed
|
||||
if (section.isLong("seed")) {
|
||||
world.setSeed(section.getLong("seed"));
|
||||
}
|
||||
|
||||
// migrate weather
|
||||
if (section.isBoolean("allowweather")) {
|
||||
world.setEnableWeather(section.getBoolean("allowweather"));
|
||||
}
|
||||
|
||||
// migrate adjustspawn
|
||||
if (section.isBoolean("adjustspawn")) {
|
||||
world.setAdjustSpawn(section.getBoolean("adjustspawn"));
|
||||
}
|
||||
|
||||
// migrate autoload
|
||||
if (section.isBoolean("autoload")) {
|
||||
world.setAutoLoad(section.getBoolean("autoload"));
|
||||
}
|
||||
|
||||
// migrate bedrespawn
|
||||
if (section.isBoolean("bedrespawn")) {
|
||||
world.setBedRespawn(section.getBoolean("bedrespawn"));
|
||||
}
|
||||
|
||||
// migrate spawn
|
||||
if (section.isConfigurationSection("spawn")) {
|
||||
ConfigurationSection spawnSect = section.getConfigurationSection("spawn");
|
||||
Location spawnLoc = world.getSpawnLocation();
|
||||
if (spawnSect.isDouble("yaw"))
|
||||
spawnLoc.setYaw((float) spawnSect.getDouble("yaw"));
|
||||
if (spawnSect.isDouble("pitch"))
|
||||
spawnLoc.setPitch((float) spawnSect.getDouble("pitch"));
|
||||
if (spawnSect.isDouble("x"))
|
||||
spawnLoc.setX(spawnSect.getDouble("x"));
|
||||
if (spawnSect.isDouble("y"))
|
||||
spawnLoc.setY(spawnSect.getDouble("y"));
|
||||
if (spawnSect.isDouble("z"))
|
||||
spawnLoc.setZ(spawnSect.getDouble("z"));
|
||||
|
||||
world.setSpawnLocation(spawnLoc);
|
||||
}
|
||||
|
||||
newValues.put(entry.getKey(), world);
|
||||
wasChanged = true;
|
||||
} else {
|
||||
// huh?
|
||||
this.log(Level.WARNING, "Removing unknown entry in the config: " + entry);
|
||||
// just don't add to newValues
|
||||
wasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (wasChanged) {
|
||||
// clear config
|
||||
wconf.set("worlds", null);
|
||||
|
||||
// and rebuild it
|
||||
ConfigurationSection rootSection = wconf.createSection("worlds");
|
||||
for (Map.Entry<String, Object> entry : newValues.entrySet()) {
|
||||
rootSection.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
try {
|
||||
wconf.save(new File(getDataFolder(), "worlds.yml"));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -422,6 +678,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.saveMVConfigs();
|
||||
debugLog.close();
|
||||
this.banker = null;
|
||||
this.bank = null;
|
||||
@@ -489,18 +746,16 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
* @param msg The message to log.
|
||||
*/
|
||||
public static void staticLog(Level level, String msg) {
|
||||
if (level == Level.FINE && config.getGlobalDebug() >= 1) {
|
||||
if (level == Level.FINE && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 1) {
|
||||
staticDebugLog(Level.INFO, msg);
|
||||
return;
|
||||
} else if (level == Level.FINER && config.getGlobalDebug() >= 2) {
|
||||
} else if (level == Level.FINER && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 2) {
|
||||
staticDebugLog(Level.INFO, msg);
|
||||
return;
|
||||
} else if (level == Level.FINEST && config.getGlobalDebug() >= 3) {
|
||||
} else if (level == Level.FINEST && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 3) {
|
||||
staticDebugLog(Level.INFO, msg);
|
||||
return;
|
||||
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
|
||||
LOGGER.log(level, String.format("%s %s", LOG_TAG, msg));
|
||||
debugLog.log(level, String.format("%s %s", LOG_TAG, msg));
|
||||
String message = LOG_TAG + " " + msg;
|
||||
LOGGER.log(level, message);
|
||||
debugLog.log(level, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,8 +767,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
* @param msg The message
|
||||
*/
|
||||
public static void staticDebugLog(Level level, String msg) {
|
||||
LOGGER.log(level, "[MVCore-Debug] " + msg);
|
||||
debugLog.log(level, "[MVCore-Debug] " + msg);
|
||||
debugLog.log(level, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,7 +776,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
@Override
|
||||
public String getAuthors() {
|
||||
String authors = "";
|
||||
ArrayList<String> auths = this.getDescription().getAuthors();
|
||||
List<String> auths = this.getDescription().getAuthors();
|
||||
if (auths.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
@@ -662,9 +916,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.serverFolder = newServerFolder;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initializes Spout.
|
||||
*/
|
||||
* /
|
||||
public void setSpout() {
|
||||
this.spoutInterface = new SpoutInterface();
|
||||
this.commandHandler.registerCommand(new SpoutCommand(this));
|
||||
@@ -674,10 +929,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
* Gets our {@link SpoutInterface}.
|
||||
*
|
||||
* @return The {@link SpoutInterface} we're using.
|
||||
*/
|
||||
* /
|
||||
public SpoutInterface getSpout() {
|
||||
return this.spoutInterface;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -864,6 +1120,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
*/
|
||||
@Deprecated
|
||||
public static MultiverseCoreConfiguration getStaticConfig() {
|
||||
return config;
|
||||
return MultiverseCoreConfiguration.getInstance();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,43 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
||||
|
||||
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Our configuration.
|
||||
*/
|
||||
public class MultiverseCoreConfiguration extends SerializationConfig implements MultiverseCoreConfig {
|
||||
private static MultiverseCoreConfiguration instance;
|
||||
|
||||
/**
|
||||
* Sets the statically saved instance.
|
||||
* @param instance The new instance.
|
||||
*/
|
||||
public static void setInstance(MultiverseCoreConfiguration instance) {
|
||||
MultiverseCoreConfiguration.instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if the static instance of config is set.
|
||||
*/
|
||||
public static boolean isSet() {
|
||||
return instance != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the statically saved instance.
|
||||
* @return The statically saved instance.
|
||||
*/
|
||||
public static MultiverseCoreConfiguration getInstance() {
|
||||
if (instance == null)
|
||||
throw new IllegalStateException("The instance wasn't set!");
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Property
|
||||
private boolean enforceaccess;
|
||||
@Property
|
||||
@@ -34,10 +61,12 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
|
||||
public MultiverseCoreConfiguration() {
|
||||
super();
|
||||
MultiverseCoreConfiguration.setInstance(this);
|
||||
}
|
||||
|
||||
public MultiverseCoreConfiguration(Map<String, Object> values) {
|
||||
super(values);
|
||||
MultiverseCoreConfiguration.setInstance(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +87,18 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setConfigProperty(String property, String value) {
|
||||
try {
|
||||
return this.setProperty(property, value, true);
|
||||
} catch (NoSuchPropertyException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// And here we go:
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface MVDestination {
|
||||
boolean isThisType(JavaPlugin plugin, String destination);
|
||||
|
||||
/**
|
||||
* Returns the location a specific entity will spawn at.
|
||||
* Returns the location a specific entity will spawn at when being teleported to this Destination.
|
||||
* <p>
|
||||
* To just retrieve the location as it is stored you can just pass null, but be warned some destinations may return
|
||||
* null back to you if you do this. It is always safer to pass an actual entity. This is used so things like
|
||||
|
||||
@@ -12,7 +12,7 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
||||
* @param value The value.
|
||||
* @return True on success, false if the operation failed.
|
||||
*/
|
||||
boolean setProperty(String property, String value);
|
||||
boolean setConfigProperty(String property, String value);
|
||||
|
||||
/**
|
||||
* Sets portalCooldown.
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.utils.DebugLog;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
|
||||
/**
|
||||
* Make things easier for MV-Plugins!
|
||||
*/
|
||||
public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin {
|
||||
private MultiverseCore core;
|
||||
/**
|
||||
* Prefix for standard log entrys.
|
||||
*/
|
||||
protected String logTag;
|
||||
private DebugLog debugLog;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Note: You can't override this, use {@link #onPluginEnable()} instead!
|
||||
* @see #onPluginEnable()
|
||||
*/
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
MultiverseCore theCore = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core");
|
||||
if (theCore == null) {
|
||||
this.getLogger().severe("Core not found! The plugin dev needs to add a dependency!");
|
||||
this.getLogger().severe("Disabling!");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (theCore.getProtocolVersion() < this.getProtocolVersion()) {
|
||||
this.getLogger().severe("You need a newer version of Multiverse-Core!");
|
||||
this.getLogger().severe("Disabling!");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
this.setCore(theCore);
|
||||
|
||||
// Turn on Logging
|
||||
this.getServer().getLogger().info(String.format("%s - Version %s enabled - By %s",
|
||||
this.getDescription().getName(), this.getDescription().getVersion(), getAuthors()));
|
||||
getDataFolder().mkdirs();
|
||||
File debugLogFile = new File(getDataFolder(), "debug.log");
|
||||
try {
|
||||
debugLogFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
debugLog = new DebugLog("Multiverse-Adventure", getDataFolder() + File.separator + "debug.log");
|
||||
debugLog.setTag(String.format("[%s-Debug]", this.getDescription().getName()));
|
||||
|
||||
this.onPluginEnable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the Authors Array into a readable String with ',' and 'and'.
|
||||
*
|
||||
* @return The readable authors-{@link String}
|
||||
*/
|
||||
protected String getAuthors() {
|
||||
String authors = "";
|
||||
List<String> auths = this.getDescription().getAuthors();
|
||||
if (auths.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (auths.size() == 1) {
|
||||
return auths.get(0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < auths.size(); i++) {
|
||||
if (i == this.getDescription().getAuthors().size() - 1) {
|
||||
authors += " and " + this.getDescription().getAuthors().get(i);
|
||||
} else {
|
||||
authors += ", " + this.getDescription().getAuthors().get(i);
|
||||
}
|
||||
}
|
||||
return authors.substring(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the plugin is enabled.
|
||||
* @see #onEnable()
|
||||
*/
|
||||
protected abstract void onPluginEnable();
|
||||
|
||||
/**
|
||||
* You can register commands here.
|
||||
* @param handler The CommandHandler.
|
||||
*/
|
||||
protected abstract void registerCommands(CommandHandler handler);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!this.isEnabled()) {
|
||||
sender.sendMessage("This plugin is Disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
ArrayList<String> allArgs = new ArrayList<String>(args.length + 1);
|
||||
allArgs.add(command.getName());
|
||||
allArgs.addAll(Arrays.asList(args));
|
||||
return this.getCore().getCommandHandler().locateAndRunCommand(sender, allArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, String msg) {
|
||||
int debugLevel = this.getCore().getMVConfig().getGlobalDebug();
|
||||
if ((level == Level.FINE && debugLevel >= 1) || (level == Level.FINER && debugLevel >= 2)
|
||||
|| (level == Level.FINEST && debugLevel >= 3)) {
|
||||
debugLog.log(level, msg);
|
||||
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
|
||||
String message = new StringBuilder(getLogTag()).append(msg).toString();
|
||||
this.getServer().getLogger().log(level, message);
|
||||
debugLog.log(level, message);
|
||||
}
|
||||
}
|
||||
|
||||
private String getLogTag() {
|
||||
if (logTag == null)
|
||||
logTag = String.format("[%s]", this.getDescription().getName());
|
||||
return logTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the debug log-tag.
|
||||
* @param tag The new tag.
|
||||
*/
|
||||
protected final void setDebugLogTag(String tag) {
|
||||
this.debugLog.setTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String dumpVersionInfo(String buffer) {
|
||||
throw new UnsupportedOperationException("This is gone.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final MultiverseCore getCore() {
|
||||
if (this.core == null)
|
||||
throw new IllegalStateException("Core is null!");
|
||||
return this.core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setCore(MultiverseCore core) {
|
||||
this.core = core;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.configuration.MVConfigProperty;
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
|
||||
@@ -26,7 +25,6 @@ import java.util.List;
|
||||
* The API for a Multiverse Handled World.
|
||||
*/
|
||||
public interface MultiverseWorld {
|
||||
|
||||
/**
|
||||
* Returns the Bukkit world object that this world describes.
|
||||
*
|
||||
@@ -35,79 +33,24 @@ public interface MultiverseWorld {
|
||||
World getCBWorld();
|
||||
|
||||
/**
|
||||
* Adds the property to the given value.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
* Gets the name of this world. The name cannot be changed.
|
||||
* <p>
|
||||
* Note for plugin developers: Usually {@link #getAlias()}
|
||||
* is what you want to use instead of this method.
|
||||
*
|
||||
* @param property The name of a world property to set.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @param sender The sender who wants this value to be set.
|
||||
* @return True if the value was set, false if not.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
* @return The name of the world as a String.
|
||||
*/
|
||||
boolean setProperty(String property, String value, CommandSender sender) throws PropertyDoesNotExistException;
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the actual MVConfigProperty from this world.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
* Gets the type of this world. As of 1.2 this will be:
|
||||
* FLAT, NORMAL or VERSION_1_1
|
||||
* <p>
|
||||
* This is <b>not</b> the generator.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
* @return A valid MVWorldProperty.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
* @deprecated Use {@link #getProperty(String, Class)} instead
|
||||
* @return The Type of this world.
|
||||
*/
|
||||
@Deprecated
|
||||
MVConfigProperty<?> getProperty(String property) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Gets the string representation of a property.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
* @return A valid MVWorldProperty.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
String getPropertyValue(String property) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Gets the actual MVConfigProperty from this world.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
* @param expected The type of the expected property. Use Object.class if this doesn't matter for you.
|
||||
* @param <T> The type of the expected property.
|
||||
*
|
||||
* @return A valid MVWorldProperty.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
<T> MVConfigProperty<T> getProperty(String property, Class<T> expected) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to clear.
|
||||
* @return True if it was cleared, false if not.
|
||||
*/
|
||||
boolean clearVariable(String property);
|
||||
|
||||
/**
|
||||
* Adds a value to the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to add a value to.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @return True if the value was added, false if not.
|
||||
*/
|
||||
boolean addToVariable(String property, String value);
|
||||
|
||||
/**
|
||||
* Removes a value from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to remove a value
|
||||
* from.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @return True if the value was removed, false if not.
|
||||
*/
|
||||
boolean removeFromVariable(String property, String value);
|
||||
WorldType getWorldType();
|
||||
|
||||
/**
|
||||
* Gets the environment of this world.
|
||||
@@ -125,27 +68,168 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
void setEnvironment(World.Environment environment);
|
||||
|
||||
/**
|
||||
* Gets the difficulty of this world.
|
||||
*
|
||||
* @return The difficulty of this world.
|
||||
*/
|
||||
Difficulty getDifficulty();
|
||||
|
||||
/**
|
||||
* Sets the difficulty of this world and returns true if success.
|
||||
* Valid string values are either an integer of difficulty(0-3) or
|
||||
* the name that resides in the Bukkit enum, ex. {@code PEACEFUL}
|
||||
*
|
||||
* @param difficulty The difficulty to set the world to as a string.
|
||||
* @return True if success, false if the provided string
|
||||
* could not be translated to a difficulty.
|
||||
* @deprecated Use {@link #setDifficulty(Difficulty)} or, if you have to
|
||||
* pass a string, use {@link #setPropertyValue(String, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setDifficulty(String difficulty);
|
||||
|
||||
/**
|
||||
* Sets the difficulty of this world and returns {@code true} on success.
|
||||
* Valid string values are either an integer of difficulty(0-3) or
|
||||
* the name that resides in the Bukkit enum, ex. PEACEFUL
|
||||
*
|
||||
* @param difficulty The new difficulty.
|
||||
* @return True if success, false if the operation failed... for whatever reason.
|
||||
*/
|
||||
boolean setDifficulty(Difficulty difficulty);
|
||||
|
||||
/**
|
||||
* Gets the world seed of this world.
|
||||
*
|
||||
* @return The Long version of the seed.
|
||||
*/
|
||||
Long getSeed();
|
||||
long getSeed();
|
||||
|
||||
/**
|
||||
* Sets the seed of this world.
|
||||
*
|
||||
* @param seed A Long that is the seed.
|
||||
*/
|
||||
void setSeed(Long seed);
|
||||
void setSeed(long seed);
|
||||
|
||||
/**
|
||||
* Gets the name of this world. This cannot be changed.
|
||||
* Gets the generator of this world.
|
||||
*
|
||||
* @return The name of the world as a String.
|
||||
* @return The name of the generator.
|
||||
*/
|
||||
String getName();
|
||||
String getGenerator();
|
||||
|
||||
/**
|
||||
* Sets the generator of this world.
|
||||
*
|
||||
* @param generator The new generator's name.
|
||||
*/
|
||||
void setGenerator(String generator);
|
||||
|
||||
/**
|
||||
* Gets the help-message for a property.
|
||||
* @param property The name of the property.
|
||||
* @return The help-message.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found.
|
||||
*/
|
||||
String getPropertyHelp(String property) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Gets a property as {@link String}.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
* @return The string-representation of that property.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
String getPropertyValue(String property) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Sets a property to a given value.
|
||||
*
|
||||
* @param property The name of a world property to set.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @return True if the value was set, false if not.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
boolean setPropertyValue(String property, String value) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Gets the actual MVConfigProperty from this world.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
* @param expected The type of the expected property. Use Object.class if this doesn't matter for you.
|
||||
* @param <T> The type of the expected property.
|
||||
*
|
||||
* @return A valid MVWorldProperty.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
* @deprecated We don't use {@link com.onarandombox.MultiverseCore.configuration.MVConfigProperty} any longer!
|
||||
*/
|
||||
@Deprecated
|
||||
<T> com.onarandombox.MultiverseCore.configuration.MVConfigProperty<T> getProperty(String property, Class<T> expected) throws PropertyDoesNotExistException;
|
||||
|
||||
// old config
|
||||
/**
|
||||
* Adds the property to the given value.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to set.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @param sender The sender who wants this value to be set.
|
||||
* @return True if the value was set, false if not.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
* @deprecated Use {@link #setPropertyValue(String, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setProperty(String property, String value, CommandSender sender) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Adds a value to the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to add a value to.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @return True if the value was added, false if not.
|
||||
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean addToVariable(String property, String value);
|
||||
|
||||
/**
|
||||
* Removes a value from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to remove a value
|
||||
* from.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @return True if the value was removed, false if not.
|
||||
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean removeFromVariable(String property, String value);
|
||||
|
||||
/**
|
||||
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to clear.
|
||||
* @return True if it was cleared, false if not.
|
||||
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean clearVariable(String property);
|
||||
|
||||
/**
|
||||
* Clears a list property (sets it to []).
|
||||
*
|
||||
* @param property The property to clear.
|
||||
* @return True if success, false if fail.
|
||||
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean clearList(String property);
|
||||
// end of old config stuff
|
||||
|
||||
// permission stuff
|
||||
/**
|
||||
* Gets the lowercased name of the world. This method is required, since the permissables
|
||||
* lowercase all permissions when recalculating.
|
||||
@@ -158,6 +242,21 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
String getPermissibleName();
|
||||
|
||||
/**
|
||||
* Gets the permission required to enter this world.
|
||||
*
|
||||
* @return The permission required to be exempt from charges to/from this world.
|
||||
*/
|
||||
Permission getAccessPermission();
|
||||
|
||||
/**
|
||||
* Gets the permission required to be exempt when entering.
|
||||
*
|
||||
* @return The permission required to be exempt when entering.
|
||||
*/
|
||||
Permission getExemptPermission();
|
||||
// end of permission stuff
|
||||
|
||||
/**
|
||||
* Gets the alias of this world.
|
||||
* <p>
|
||||
@@ -174,6 +273,13 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
void setAlias(String alias);
|
||||
|
||||
/**
|
||||
* Gets the color that this world's name/alias will display as.
|
||||
*
|
||||
* @return The color of this world.
|
||||
*/
|
||||
ChatColor getColor();
|
||||
|
||||
/**
|
||||
* Sets the color that this world's name/alias will display as.
|
||||
*
|
||||
@@ -183,18 +289,29 @@ public interface MultiverseWorld {
|
||||
boolean setColor(String color);
|
||||
|
||||
/**
|
||||
* Gets the color that this world's name/alias will display as.
|
||||
* Gets the style that this world's name/alias will display as.
|
||||
*
|
||||
* @return The color of this world.
|
||||
* @return The style of this world. {@code null} for "normal" style.
|
||||
*/
|
||||
ChatColor getColor();
|
||||
ChatColor getStyle();
|
||||
|
||||
/**
|
||||
* Sets the style that this world's name/alias will display as.
|
||||
*
|
||||
* @param style A valid style name.
|
||||
* @return True if the style was set, false if not.
|
||||
*/
|
||||
boolean setStyle(String style);
|
||||
|
||||
/**
|
||||
* Tells you if someone entered a valid color.
|
||||
*
|
||||
* @param color A string that may translate to a color.
|
||||
* @return True if it is a color, false if not.
|
||||
*
|
||||
* @deprecated This has been moved: {@link com.onarandombox.MultiverseCore.enums.EnglishChatColor#isValidAliasColor(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isValidAliasColor(String color);
|
||||
|
||||
/**
|
||||
@@ -204,6 +321,7 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
String getColoredWorldString();
|
||||
|
||||
// animals&monster stuff
|
||||
/**
|
||||
* Gets whether or not animals are allowed to spawn in this world.
|
||||
*
|
||||
@@ -211,6 +329,22 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
boolean canAnimalsSpawn();
|
||||
|
||||
/**
|
||||
* Sets whether or not animals can spawn.
|
||||
* If there are values in {@link #getAnimalList()} and this is false,
|
||||
* those animals become the exceptions, and will spawn
|
||||
*
|
||||
* @param allowAnimalSpawn True to allow spawning of monsters, false to prevent.
|
||||
*/
|
||||
void setAllowAnimalSpawn(boolean allowAnimalSpawn);
|
||||
|
||||
/**
|
||||
* Returns a list of animals. This list always negates the {@link #canAnimalsSpawn()} result.
|
||||
*
|
||||
* @return A list of animals that will spawn if {@link #canAnimalsSpawn()} is false.
|
||||
*/
|
||||
List<String> getAnimalList();
|
||||
|
||||
/**
|
||||
* Gets whether or not monsters are allowed to spawn in this world.
|
||||
*
|
||||
@@ -219,7 +353,31 @@ public interface MultiverseWorld {
|
||||
boolean canMonstersSpawn();
|
||||
|
||||
/**
|
||||
* Turn pvp on or off. This setting is used to set the world's PVP mode, and thus relies on fakePVP
|
||||
* Sets whether or not monsters can spawn.
|
||||
* If there are values in {@link #getMonsterList()} and this is false,
|
||||
* those monsters become the exceptions, and will spawn
|
||||
*
|
||||
* @param allowMonsterSpawn True to allow spawning of monsters, false to prevent.
|
||||
*/
|
||||
void setAllowMonsterSpawn(boolean allowMonsterSpawn);
|
||||
|
||||
/**
|
||||
* Returns a list of monsters. This list always negates the {@link #canMonstersSpawn()} result.
|
||||
*
|
||||
* @return A list of monsters that will spawn if {@link #canMonstersSpawn()} is false.
|
||||
*/
|
||||
List<String> getMonsterList();
|
||||
// end of animal&monster stuff
|
||||
|
||||
/**
|
||||
* Gets whether or not PVP is enabled in this world in some form (fake or not).
|
||||
*
|
||||
* @return True if players can take damage from other players.
|
||||
*/
|
||||
boolean isPVPEnabled();
|
||||
|
||||
/**
|
||||
* Turn pvp on or off. This setting is used to set the world's PVP mode.
|
||||
*
|
||||
* @param pvpMode True to enable PVP damage, false to disable it.
|
||||
*/
|
||||
@@ -234,13 +392,6 @@ public interface MultiverseWorld {
|
||||
@Deprecated
|
||||
boolean getFakePVP();
|
||||
|
||||
/**
|
||||
* Gets whether or not PVP is enabled in this world in some form (fake or not).
|
||||
*
|
||||
* @return True if players can take damage from other players.
|
||||
*/
|
||||
boolean isPVPEnabled();
|
||||
|
||||
/**
|
||||
* Gets whether or not this world will display in chat, mvw and mvl regardless if a user has the
|
||||
* access permissions to go to this world.
|
||||
@@ -257,6 +408,13 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
void setHidden(boolean hidden);
|
||||
|
||||
/**
|
||||
* Gets whether weather is enabled in this world.
|
||||
*
|
||||
* @return True if weather events will occur, false if not.
|
||||
*/
|
||||
boolean isWeatherEnabled();
|
||||
|
||||
/**
|
||||
* Sets whether or not there will be weather events in a given world.
|
||||
* If set to false, Multiverse will disable the weather in the world immediately.
|
||||
@@ -266,11 +424,11 @@ public interface MultiverseWorld {
|
||||
void setEnableWeather(boolean enableWeather);
|
||||
|
||||
/**
|
||||
* Gets whether weather is enabled in this world.
|
||||
* Gets whether or not CraftBukkit is keeping the chunks for this world in memory.
|
||||
*
|
||||
* @return True if weather events will occur, false if not.
|
||||
* @return True if CraftBukkit is keeping spawn chunks in memory.
|
||||
*/
|
||||
boolean isWeatherEnabled();
|
||||
boolean isKeepingSpawnInMemory();
|
||||
|
||||
/**
|
||||
* If true, tells Craftbukkit to keep a worlds spawn chunks loaded in memory (default: true)
|
||||
@@ -282,29 +440,11 @@ public interface MultiverseWorld {
|
||||
void setKeepSpawnInMemory(boolean keepSpawnInMemory);
|
||||
|
||||
/**
|
||||
* Gets whether or not CraftBukkit is keeping the chunks for this world in memory.
|
||||
* Gets the spawn location of this world.
|
||||
*
|
||||
* @return True if CraftBukkit is keeping spawn chunks in memory.
|
||||
* @return The spawn location of this world.
|
||||
*/
|
||||
boolean isKeepingSpawnInMemory();
|
||||
|
||||
/**
|
||||
* Sets the difficulty of this world and returns true if success.
|
||||
* Valid string values are either an integer of difficulty(0-3) or
|
||||
* the name that resides in the Bukkit enum, ex. PEACEFUL
|
||||
*
|
||||
* @param difficulty The difficulty to set the world to as a string.
|
||||
* @return True if success, false if the provided string
|
||||
* could not be translated to a difficulty.
|
||||
*/
|
||||
boolean setDifficulty(String difficulty);
|
||||
|
||||
/**
|
||||
* Gets the difficulty of this world.
|
||||
*
|
||||
* @return The difficulty of this world.
|
||||
*/
|
||||
Difficulty getDifficulty();
|
||||
Location getSpawnLocation();
|
||||
|
||||
/**
|
||||
* Sets the spawn location for a world.
|
||||
@@ -314,11 +454,11 @@ public interface MultiverseWorld {
|
||||
void setSpawnLocation(Location spawnLocation);
|
||||
|
||||
/**
|
||||
* Gets the spawn location of this world.
|
||||
* Gets whether or not the hunger level of players will go down in a world.
|
||||
*
|
||||
* @return The spawn location of this world.
|
||||
* @return True if it will go down, false if it will remain steady.
|
||||
*/
|
||||
Location getSpawnLocation();
|
||||
boolean getHunger();
|
||||
|
||||
/**
|
||||
* Sets whether or not the hunger level of players will go down in a world.
|
||||
@@ -328,22 +468,6 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
void setHunger(boolean hungerEnabled);
|
||||
|
||||
/**
|
||||
* Gets whether or not the hunger level of players will go down in a world.
|
||||
*
|
||||
* @return True if it will go down, false if it will remain steady.
|
||||
*/
|
||||
boolean getHunger();
|
||||
|
||||
/**
|
||||
* Sets the game mode of this world.
|
||||
*
|
||||
* @param gameMode A valid game mode string (either
|
||||
* an int ex. 0 or a string ex. creative).
|
||||
* @return True if the game mode was successfully changed, false if not.
|
||||
*/
|
||||
boolean setGameMode(String gameMode);
|
||||
|
||||
/**
|
||||
* Gets the GameMode of this world.
|
||||
*
|
||||
@@ -352,18 +476,31 @@ public interface MultiverseWorld {
|
||||
GameMode getGameMode();
|
||||
|
||||
/**
|
||||
* Gets the permission required to enter this world.
|
||||
* Sets the game mode of this world.
|
||||
*
|
||||
* @return The permission required to be exempt from charges to/from this world.
|
||||
* @param gameMode A valid game mode string (either
|
||||
* an int ex. 0 or a string ex. creative).
|
||||
* @return True if the game mode was successfully changed, false if not.
|
||||
* @deprecated Use {@link #setGameMode(GameMode)} instead. If you have to
|
||||
* pass a string, use {@link #setPropertyValue(String, String)}.
|
||||
*/
|
||||
Permission getAccessPermission();
|
||||
@Deprecated
|
||||
boolean setGameMode(String gameMode);
|
||||
|
||||
/**
|
||||
* Gets the permission required to be exempt when entering.
|
||||
* Sets the game mode of this world.
|
||||
*
|
||||
* @return The permission required to be exempt when entering.
|
||||
* @param gameMode The new {@link GameMode}.
|
||||
* @return True if the game mode was successfully changed, false if not.
|
||||
*/
|
||||
Permission getExemptPermission();
|
||||
boolean setGameMode(GameMode gameMode);
|
||||
|
||||
/**
|
||||
* Gets the amount of currency it requires to enter this world.
|
||||
*
|
||||
* @return The amount it costs to enter this world.
|
||||
*/
|
||||
double getPrice();
|
||||
|
||||
/**
|
||||
* Sets the price for entry to this world.
|
||||
@@ -375,11 +512,11 @@ public interface MultiverseWorld {
|
||||
void setPrice(double price);
|
||||
|
||||
/**
|
||||
* Gets the amount of currency it requires to enter this world.
|
||||
* Gets the Type of currency that will be used when users enter this world.
|
||||
*
|
||||
* @return The amount it costs to enter this world.
|
||||
* @return The Type of currency that will be used when users enter this world.
|
||||
*/
|
||||
double getPrice();
|
||||
int getCurrency();
|
||||
|
||||
/**
|
||||
* Sets the type of item that will be required given the price is not 0.
|
||||
@@ -390,11 +527,11 @@ public interface MultiverseWorld {
|
||||
void setCurrency(int item);
|
||||
|
||||
/**
|
||||
* Gets the Type of currency that will be used when users enter this world.
|
||||
* Gets the world players will respawn in if they die in this one.
|
||||
*
|
||||
* @return The Type of currency that will be used when users enter this world.
|
||||
* @return A world that exists on the server.
|
||||
*/
|
||||
int getCurrency();
|
||||
World getRespawnToWorld();
|
||||
|
||||
/**
|
||||
* Sets the world players will respawn in if they die in this one.
|
||||
@@ -406,11 +543,12 @@ public interface MultiverseWorld {
|
||||
boolean setRespawnToWorld(String respawnWorld);
|
||||
|
||||
/**
|
||||
* Gets the world players will respawn in if they die in this one.
|
||||
* Gets the scaling value of this world.Really only has an effect if you use
|
||||
* Multiverse-NetherPortals.
|
||||
*
|
||||
* @return A world that exists on the server.
|
||||
* @return This world's non-negative, non-zero scale.
|
||||
*/
|
||||
World getRespawnToWorld();
|
||||
double getScaling();
|
||||
|
||||
/**
|
||||
* Sets the scale of this world. Really only has an effect if you use
|
||||
@@ -422,60 +560,11 @@ public interface MultiverseWorld {
|
||||
boolean setScaling(double scaling);
|
||||
|
||||
/**
|
||||
* Gets the scaling value of this world.Really only has an effect if you use
|
||||
* Multiverse-NetherPortals.
|
||||
* Gets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
||||
*
|
||||
* @return This world's non-negative, non-zero scale.
|
||||
* @return True if the world should heal (default), false if not.
|
||||
*/
|
||||
double getScaling();
|
||||
|
||||
/**
|
||||
* Gets a list of all the worlds that players CANNOT travel to from this world,
|
||||
* regardless of their access permissions.
|
||||
*
|
||||
* @return A List of world names.
|
||||
*/
|
||||
List<String> getWorldBlacklist();
|
||||
|
||||
/**
|
||||
* Returns a list of animals. This list always negates the {@link #canAnimalsSpawn()} result.
|
||||
*
|
||||
* @return A list of animals that will spawn if {@link #canAnimalsSpawn()} is false.
|
||||
*/
|
||||
List<String> getAnimalList();
|
||||
|
||||
/**
|
||||
* Sets whether or not animals can spawn.
|
||||
* If there are values in {@link #getAnimalList()} and this is false,
|
||||
* those animals become the exceptions, and will spawn
|
||||
*
|
||||
* @param allowAnimalSpawn True to allow spawning of monsters, false to prevent.
|
||||
*/
|
||||
void setAllowAnimalSpawn(boolean allowAnimalSpawn);
|
||||
|
||||
/**
|
||||
* Returns a list of monsters. This list always negates the {@link #canMonstersSpawn()} ()} result.
|
||||
*
|
||||
* @return A list of monsters that will spawn if {@link #canMonstersSpawn()} is false.
|
||||
*/
|
||||
List<String> getMonsterList();
|
||||
|
||||
/**
|
||||
* Sets whether or not monsters can spawn.
|
||||
* If there are values in {@link #getMonsterList()} and this is false,
|
||||
* those monsters become the exceptions, and will spawn
|
||||
*
|
||||
* @param allowMonsterSpawn True to allow spawning of monsters, false to prevent.
|
||||
*/
|
||||
void setAllowMonsterSpawn(boolean allowMonsterSpawn);
|
||||
|
||||
/**
|
||||
* Clears a list property (sets it to []).
|
||||
*
|
||||
* @param property The property to clear.
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
boolean clearList(String property);
|
||||
boolean getAutoHeal();
|
||||
|
||||
/**
|
||||
* Sets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
||||
@@ -485,11 +574,11 @@ public interface MultiverseWorld {
|
||||
void setAutoHeal(boolean heal);
|
||||
|
||||
/**
|
||||
* Gets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
||||
* Gets whether or not Multiverse should auto-adjust the spawn for this world.
|
||||
*
|
||||
* @return True if the world should heal (default), false if not.
|
||||
* @return True if Multiverse should adjust the spawn, false if not.
|
||||
*/
|
||||
boolean getAutoHeal();
|
||||
boolean getAdjustSpawn();
|
||||
|
||||
/**
|
||||
* Sets whether or not Multiverse should auto-adjust the spawn for this world.
|
||||
@@ -499,11 +588,11 @@ public interface MultiverseWorld {
|
||||
void setAdjustSpawn(boolean adjust);
|
||||
|
||||
/**
|
||||
* Gets whether or not Multiverse should auto-adjust the spawn for this world.
|
||||
* Gets whether or not Multiverse should auto-load this world.
|
||||
*
|
||||
* @return True if Multiverse should adjust the spawn, false if not.
|
||||
* @return True if Multiverse should auto-load this world.
|
||||
*/
|
||||
boolean getAdjustSpawn();
|
||||
boolean getAutoLoad();
|
||||
|
||||
/**
|
||||
* Sets whether or not Multiverse should auto-load this world.
|
||||
@@ -515,11 +604,12 @@ public interface MultiverseWorld {
|
||||
void setAutoLoad(boolean autoLoad);
|
||||
|
||||
/**
|
||||
* Gets whether or not Multiverse should auto-load this world.
|
||||
* Gets whether or not a player who dies in this world will respawn in their
|
||||
* bed or follow the normal respawn pattern.
|
||||
*
|
||||
* @return True if Multiverse should auto-load this world.
|
||||
* @return True if players dying in this world should respawn at their bed.
|
||||
*/
|
||||
boolean getAutoLoad();
|
||||
boolean getBedRespawn();
|
||||
|
||||
/**
|
||||
* Sets whether or not a player who dies in this world will respawn in their
|
||||
@@ -532,19 +622,10 @@ public interface MultiverseWorld {
|
||||
void setBedRespawn(boolean autoLoad);
|
||||
|
||||
/**
|
||||
* Gets whether or not a player who dies in this world will respawn in their
|
||||
* bed or follow the normal respawn pattern.
|
||||
*
|
||||
* @return True if players dying in this world should respawn at their bed.
|
||||
* Same as {@link #getTime()}, but returns a string.
|
||||
* @return The time as a short string: 12:34pm
|
||||
*/
|
||||
boolean getBedRespawn();
|
||||
|
||||
/**
|
||||
* Gets all the names of all properties that can be SET.
|
||||
*
|
||||
* @return All property names, with alternating colors.
|
||||
*/
|
||||
String getAllPropertyNames();
|
||||
String getTime();
|
||||
|
||||
/**
|
||||
* Sets the current time in a world.
|
||||
@@ -559,22 +640,6 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
boolean setTime(String timeAsString);
|
||||
|
||||
/**
|
||||
* Same as {@link #getTime()}, but returns a string.
|
||||
* @return The time as a short string: 12:34pm
|
||||
*/
|
||||
String getTime();
|
||||
|
||||
/**
|
||||
* Gets the type of this world. As of 1.1-R1 this will be:
|
||||
* FLAT or NORMAL
|
||||
* <p>
|
||||
* This is *not* the generator.
|
||||
*
|
||||
* @return The Type of this world.
|
||||
*/
|
||||
WorldType getWorldType();
|
||||
|
||||
/**
|
||||
* Sets The types of portals that are allowed in this world.
|
||||
*
|
||||
@@ -588,4 +653,20 @@ public interface MultiverseWorld {
|
||||
* @return The type of portals that are allowed.
|
||||
*/
|
||||
AllowedPortalType getAllowedPortals();
|
||||
|
||||
// properties that are not "getter+setter" style
|
||||
/**
|
||||
* Gets a list of all the worlds that players CANNOT travel to from this world,
|
||||
* regardless of their access permissions.
|
||||
*
|
||||
* @return A List of world names.
|
||||
*/
|
||||
List<String> getWorldBlacklist();
|
||||
|
||||
/**
|
||||
* Gets all the names of all properties that can be SET.
|
||||
*
|
||||
* @return All property names, with alternating colors.
|
||||
*/
|
||||
String getAllPropertyNames();
|
||||
}
|
||||
@@ -45,18 +45,13 @@ public class CheckCommand extends MultiverseCommand {
|
||||
}
|
||||
MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1));
|
||||
if (dest instanceof InvalidDestination) {
|
||||
sender.sendMessage("You asked if '" + args.get(0) + "' could go to " + ChatColor.GREEN + args.get(0) + ChatColor.WHITE + ",");
|
||||
sender.sendMessage(String.format("You asked if '%s' could go to %s%s%s,",
|
||||
args.get(0), ChatColor.GREEN, args.get(0), ChatColor.WHITE));
|
||||
sender.sendMessage("but I couldn't find a Destination of that name? Did you type it correctly?");
|
||||
return;
|
||||
}
|
||||
|
||||
MVPermissions perms = this.plugin.getMVPerms();
|
||||
if (perms.canEnterDestination(p, dest)) {
|
||||
sender.sendMessage(ChatColor.GREEN + args.get(0) + ChatColor.WHITE + " can travel to " + ChatColor.GREEN + args.get(1));
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.AQUA + args.get(0) + ChatColor.RED + " CANNOT travel to " + ChatColor.AQUA + args.get(1));
|
||||
sender.sendMessage("Please turn debug mode to 3 then watch the console to find out why!");
|
||||
sender.sendMessage("Use: " + ChatColor.GREEN + "/mv debug 3");
|
||||
}
|
||||
perms.tellMeWhyICantDoThis(sender, p, dest);
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
sender.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
if (!this.plugin.getMVConfig().setProperty(args.get(0).toLowerCase(), args.get(1))) {
|
||||
if (!this.plugin.getMVConfig().setConfigProperty(args.get(0).toLowerCase(), args.get(1))) {
|
||||
sender.sendMessage(String.format("%sSetting '%s' to '%s' failed!", ChatColor.RED, args.get(0).toLowerCase(), args.get(1)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ public class EnvironmentCommand extends MultiverseCommand {
|
||||
*/
|
||||
public static void showWorldTypes(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
|
||||
sender.sendMessage(String.format("%sNORMAL %sor %sFLAT",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA));
|
||||
sender.sendMessage(String.format("%sNORMAL%s, %sFLAT %sor %sVERSION_1_1",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.GOLD));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
@@ -53,7 +52,7 @@ public class ImportCommand extends MultiverseCommand {
|
||||
* @param worldFolder The File that may be a world.
|
||||
* @return True if it looks like a world, false if not.
|
||||
*/
|
||||
private boolean checkIfIsWorld(File worldFolder) {
|
||||
private static boolean checkIfIsWorld(File worldFolder) {
|
||||
if (worldFolder.isDirectory()) {
|
||||
File[] files = worldFolder.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
|
||||
@@ -75,7 +75,8 @@ public class InfoCommand extends MultiverseCommand {
|
||||
try {
|
||||
pageNum = Integer.parseInt(args.get(0)) - 1;
|
||||
} catch (NumberFormatException e) {
|
||||
pageNum = 0;
|
||||
sender.sendMessage("That world does not exist.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!");
|
||||
@@ -189,7 +190,7 @@ public class InfoCommand extends MultiverseCommand {
|
||||
return worldInfo;
|
||||
}
|
||||
|
||||
private String toCommaSeperated(List<String> list) {
|
||||
private static String toCommaSeperated(List<String> list) {
|
||||
if (list == null || list.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
@@ -215,7 +216,7 @@ public class InfoCommand extends MultiverseCommand {
|
||||
return positive ? ChatColor.GREEN : ChatColor.RED;
|
||||
}
|
||||
|
||||
private void showPage(int page, CommandSender sender, List<List<FancyText>> doc) {
|
||||
private static void showPage(int page, CommandSender sender, List<List<FancyText>> doc) {
|
||||
page = page < 0 ? 0 : page;
|
||||
page = page > doc.size() - 1 ? doc.size() - 1 : page;
|
||||
boolean altColor = false;
|
||||
|
||||
@@ -81,6 +81,7 @@ public class ModifyAddCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO fix this
|
||||
if (world.addToVariable(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA
|
||||
+ value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property);
|
||||
|
||||
@@ -75,6 +75,7 @@ public class ModifyClearCommand extends MultiverseCommand {
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/cgB2B");
|
||||
return;
|
||||
}
|
||||
// TODO fix this
|
||||
if (world.clearList(property)) {
|
||||
sender.sendMessage(property + " was cleared. It contains 0 values now.");
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was "
|
||||
|
||||
@@ -81,6 +81,7 @@ public class ModifyRemoveCommand extends MultiverseCommand {
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/4W8cY");
|
||||
return;
|
||||
}
|
||||
// TODO fix this
|
||||
if (world.removeFromVariable(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE
|
||||
+ " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property);
|
||||
|
||||
@@ -102,22 +102,21 @@ public class ModifySetCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !world.isValidAliasColor(value)) {
|
||||
if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !EnglishChatColor.isValidAliasColor(value)) {
|
||||
sender.sendMessage(value + " is not a valid color. Please pick one of the following:");
|
||||
sender.sendMessage(EnglishChatColor.getAllColors());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (world.setProperty(property, value, sender)) {
|
||||
if (world.setPropertyValue(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property
|
||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||
} else {
|
||||
sender.sendMessage(world.getProperty(property, Object.class).getHelp());
|
||||
sender.sendMessage(ChatColor.RED + world.getPropertyHelp(property));
|
||||
}
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + property + ChatColor.RED + "'");
|
||||
// TODO: Display the list
|
||||
sender.sendMessage(ChatColor.GOLD + "For a full list of thingys, see our wiki.");
|
||||
sender.sendMessage("Valid world-properties: " + world.getAllPropertyNames());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class PurgeCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
if (!worldName.equalsIgnoreCase("all") && !this.worldManager.isMVWorld(worldName)) {
|
||||
((MultiverseCore) this.plugin).showNotMVWorldMessage(sender, worldName);
|
||||
this.plugin.showNotMVWorldMessage(sender, worldName);
|
||||
sender.sendMessage("It cannot be purged.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Edit a world with spout.
|
||||
*/
|
||||
* /
|
||||
public class SpoutCommand extends MultiverseCommand {
|
||||
|
||||
public SpoutCommand(MultiverseCore plugin) {
|
||||
@@ -51,7 +51,7 @@ public class SpoutCommand extends MultiverseCommand {
|
||||
}
|
||||
PopupScreen pop = new GenericPopup();
|
||||
GenericButton button = new GenericButton("Fish");
|
||||
// TODO maybe use constants for these
|
||||
// TO-DO maybe use constants for these
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
button.setX(50);
|
||||
button.setY(50);
|
||||
@@ -63,3 +63,4 @@ public class SpoutCommand extends MultiverseCommand {
|
||||
p.getMainScreen().attachPopupScreen(pop);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -50,12 +50,8 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// Check if the command was sent from a Player.
|
||||
CommandSender teleporter = sender;
|
||||
Player teleportee = null;
|
||||
if (sender instanceof Player) {
|
||||
teleporter = (Player) sender;
|
||||
}
|
||||
|
||||
String destinationName;
|
||||
|
||||
|
||||
@@ -9,10 +9,13 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.BitlyURLShortener;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteService;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortener;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -25,6 +28,7 @@ import java.util.logging.Level;
|
||||
* Dumps version info to the console.
|
||||
*/
|
||||
public class VersionCommand extends MultiverseCommand {
|
||||
private static final URLShortener SHORTENER = new BitlyURLShortener();
|
||||
|
||||
public VersionCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
@@ -39,7 +43,7 @@ public class VersionCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
public void runCommand(final CommandSender sender, final List<String> args) {
|
||||
// Check if the command was sent from a Player.
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage("Version info dumped to console. Please check your server logs.");
|
||||
@@ -69,25 +73,30 @@ public class VersionCommand extends MultiverseCommand {
|
||||
this.plugin.getServer().getPluginManager().callEvent(versionEvent);
|
||||
|
||||
// log to console
|
||||
String data = versionEvent.getVersionInfo();
|
||||
final String data = versionEvent.getVersionInfo();
|
||||
String[] lines = data.split("\n");
|
||||
for (String line : lines) {
|
||||
this.plugin.log(Level.INFO, line);
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
String pasteUrl = "";
|
||||
if (args.get(0).equalsIgnoreCase("-p")) {
|
||||
pasteUrl = postToService(PasteServiceType.PASTIE, true, data); // private post to pastie
|
||||
} else if (args.get(0).equalsIgnoreCase("-b")) {
|
||||
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data); // private post to pastie
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
this.plugin.getServer().getScheduler().scheduleAsyncDelayedTask(this.plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.size() == 1) {
|
||||
String pasteUrl;
|
||||
if (args.get(0).equalsIgnoreCase("-p")) {
|
||||
pasteUrl = postToService(PasteServiceType.PASTIE, true, data); // private post to pastie
|
||||
} else if (args.get(0).equalsIgnoreCase("-b")) {
|
||||
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data); // private post to pastie
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
|
||||
this.plugin.log(Level.INFO, "Version info dumped here: " + pasteUrl);
|
||||
}
|
||||
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
|
||||
plugin.log(Level.INFO, "Version info dumped here: " + pasteUrl);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +109,7 @@ public class VersionCommand extends MultiverseCommand {
|
||||
private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData) {
|
||||
PasteService ps = PasteServiceFactory.getService(type, isPrivate);
|
||||
try {
|
||||
return ps.postData(ps.encodeData(pasteData), ps.getPostURL());
|
||||
return SHORTENER.shorten(ps.postData(ps.encodeData(pasteData), ps.getPostURL()));
|
||||
} catch (PasteFailedException e) {
|
||||
System.out.print(e);
|
||||
return "Error posting to service";
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -28,11 +27,14 @@ public class WhoCommand extends MultiverseCommand {
|
||||
public WhoCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Who?");
|
||||
this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD|--all]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv who");
|
||||
this.addKey("mvw");
|
||||
this.addKey("mvwho");
|
||||
this.addCommandExample("/mv who");
|
||||
this.addCommandExample(String.format("/mv who %s--all", ChatColor.GREEN));
|
||||
this.addCommandExample(String.format("/mv who %smyworld", ChatColor.GOLD));
|
||||
this.setPermission("multiverse.core.list.who", "States who is in what world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
@@ -48,57 +50,58 @@ public class WhoCommand extends MultiverseCommand {
|
||||
showAll = false;
|
||||
}
|
||||
|
||||
List<MultiverseWorld> worlds = new ArrayList<MultiverseWorld>();
|
||||
|
||||
if (args.size() > 0) {
|
||||
MultiverseWorld world = this.worldManager.getMVWorld(args.get(0));
|
||||
if (args.size() == 1) {
|
||||
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
|
||||
showAll = true;
|
||||
worlds = new ArrayList<MultiverseWorld>(this.worldManager.getMVWorlds());
|
||||
} else if (world != null) {
|
||||
if (!world.isHidden()) {
|
||||
worlds.add(world);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "World does not exist");
|
||||
// single world mode
|
||||
MultiverseWorld world = this.worldManager.getMVWorld(args.get(0));
|
||||
if (world == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That world does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.plugin.getMVPerms().canEnterWorld(p, world)) {
|
||||
sender.sendMessage(ChatColor.RED + "You aren't allowed to access to this world!");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA,
|
||||
world.getColoredWorldString(), ChatColor.AQUA));
|
||||
sender.sendMessage(buildPlayerString(world, p));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
worlds = new ArrayList<MultiverseWorld>(this.worldManager.getMVWorlds());
|
||||
}
|
||||
|
||||
if (worlds.size() == 0) {
|
||||
sender.sendMessage("Multiverse does not know about any of your worlds :(");
|
||||
} else if (worlds.size() == 1) {
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Players in" + worlds.get(0).getColoredWorldString() + ChatColor.AQUA + " ---");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.AQUA + "--- There are players in ---");
|
||||
}
|
||||
|
||||
for (MultiverseWorld world : worlds) {
|
||||
if (!(this.worldManager.isMVWorld(world.getName()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p != null && (!this.plugin.getMVPerms().canEnterWorld(p, world))) {
|
||||
continue;
|
||||
}
|
||||
List<Player> players = world.getCBWorld().getPlayers();
|
||||
|
||||
String result = "";
|
||||
if (players.size() <= 0 && !showAll) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (players.size() <= 0) {
|
||||
result = "Empty";
|
||||
} else {
|
||||
for (Player player : players) {
|
||||
result += player.getDisplayName() + " " + ChatColor.WHITE;
|
||||
// multiworld mode
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Worlds and their players ---");
|
||||
boolean shownOne = false;
|
||||
for (MultiverseWorld world : this.worldManager.getMVWorlds()) {
|
||||
if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it
|
||||
if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty
|
||||
sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world, p)));
|
||||
shownOne = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!shownOne) {
|
||||
sender.sendMessage("No worlds found.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(world.getColoredWorldString() + ChatColor.WHITE + " - " + result);
|
||||
private static String buildPlayerString(MultiverseWorld world, Player viewer) {
|
||||
List<Player> players = world.getCBWorld().getPlayers();
|
||||
if (players.size() == 0) {
|
||||
return "No players found.";
|
||||
} else {
|
||||
StringBuilder playerBuilder = new StringBuilder();
|
||||
for (Player player : players) {
|
||||
if ((viewer == null) || viewer.canSee(player))
|
||||
playerBuilder.append(player.getDisplayName()).append(", ");
|
||||
}
|
||||
String bString = playerBuilder.toString();
|
||||
return bString.substring(0, bString.length() - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A {@link String} config-property that will NOT be saved to the config.
|
||||
*/
|
||||
public class ActiveStringConfigProperty implements MVActiveConfigProperty<String> {
|
||||
private String name;
|
||||
private String value;
|
||||
private String method;
|
||||
private String help;
|
||||
|
||||
public ActiveStringConfigProperty(String name, String defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.help = help;
|
||||
this.value = defaultValue;
|
||||
this.parseValue(defaultValue);
|
||||
}
|
||||
|
||||
public ActiveStringConfigProperty(String name, String defaultValue, String help, String method) {
|
||||
this(name, defaultValue, help);
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setMethod(String methodName) {
|
||||
this.method = methodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getPropertyClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean parseValue(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.setValue(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getConfigNode() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
-135
@@ -1,135 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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 org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link Boolean} config-property.
|
||||
*/
|
||||
public class BooleanConfigProperty implements MVActiveConfigProperty<Boolean> {
|
||||
private String name;
|
||||
private Boolean value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
private String method;
|
||||
|
||||
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String help) {
|
||||
this(section, name, defaultValue, name, help);
|
||||
}
|
||||
|
||||
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.value = defaultValue;
|
||||
this.setValue(this.section.getBoolean(this.configNode, defaultValue));
|
||||
}
|
||||
|
||||
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String configNode, String help, String method) {
|
||||
this(section, name, defaultValue, configNode, help);
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(Boolean value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
this.section.set(configNode, this.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean parseValue(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
if (value.toLowerCase().equals("true") || value.toLowerCase().equals("false")) {
|
||||
this.setValue(Boolean.parseBoolean(value));
|
||||
return true;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the method that will be executed.
|
||||
*
|
||||
* @return The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method that will be executed.
|
||||
*
|
||||
* @param methodName The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public void setMethod(String methodName) {
|
||||
this.method = methodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class of the object we're looking at.
|
||||
*
|
||||
* @return the class of the object we're looking at.
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getPropertyClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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.EnglishChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link EnglishChatColor} config-property.
|
||||
*/
|
||||
public class ColorConfigProperty implements MVConfigProperty<EnglishChatColor> {
|
||||
private String name;
|
||||
private EnglishChatColor value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
|
||||
public ColorConfigProperty(ConfigurationSection section, String name, EnglishChatColor defaultValue, String help) {
|
||||
this(section, name, defaultValue, name, help);
|
||||
}
|
||||
|
||||
public ColorConfigProperty(ConfigurationSection section, String name, EnglishChatColor 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 EnglishChatColor getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(EnglishChatColor value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
this.section.set(configNode, this.value.getText());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean parseValue(String value) {
|
||||
EnglishChatColor color = EnglishChatColor.fromString(value);
|
||||
if (color == null) {
|
||||
return false;
|
||||
}
|
||||
this.setValue(color);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getConfigNode() {
|
||||
return this.configNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
-306
@@ -1,306 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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 com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/** A factory to create config properties for a given world. */
|
||||
public class ConfigPropertyFactory {
|
||||
private ConfigurationSection section;
|
||||
|
||||
public ConfigPropertyFactory(ConfigurationSection section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
// Booleans
|
||||
/**
|
||||
* 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 BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String help) {
|
||||
return new BooleanConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String node, String help) {
|
||||
return new BooleanConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ActiveBooleanConfigProperty
|
||||
*
|
||||
* This property will execute 'method' after it has been successfully set.
|
||||
*
|
||||
* @param name The name of this ConifgProperty
|
||||
* @param defaultValue The default value.
|
||||
* @param help What string is shown for help.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param method The method that should be executed.
|
||||
* @return The ActiveStringConfigProperty
|
||||
*/
|
||||
public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String help, String node, String method) {
|
||||
return new BooleanConfigProperty(this.section, name, defaultValue, help, node, method);
|
||||
}
|
||||
|
||||
// Integers
|
||||
/**
|
||||
* 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 IntegerConfigProperty getNewProperty(String name, int defaultValue, String help) {
|
||||
return new IntegerConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public IntegerConfigProperty getNewProperty(String name, int defaultValue, String node, String help) {
|
||||
return new IntegerConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
// Doubles
|
||||
/**
|
||||
* 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 DoubleConfigProperty getNewProperty(String name, double defaultValue, String help) {
|
||||
return new DoubleConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public DoubleConfigProperty getNewProperty(String name, double defaultValue, String node, String help) {
|
||||
return new DoubleConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @param method The name of the method that's used to set this property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public DoubleConfigProperty getNewProperty(String name, double defaultValue, String node, String help, String method) {
|
||||
return new DoubleConfigProperty(this.section, name, defaultValue, node, help, method);
|
||||
}
|
||||
|
||||
// Strings
|
||||
/**
|
||||
* 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 StringConfigProperty getNewProperty(String name, String defaultValue, String help) {
|
||||
return new StringConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public StringConfigProperty getNewProperty(String name, String defaultValue, String node, String help) {
|
||||
return new StringConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
// Colors
|
||||
/**
|
||||
* 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 ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String help) {
|
||||
return new ColorConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String node, String help) {
|
||||
return new ColorConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
// Difficulty
|
||||
/**
|
||||
* 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 DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String help) {
|
||||
return new DifficultyConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String node, String help) {
|
||||
return new DifficultyConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
// 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 GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String help) {
|
||||
return new GameModeConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String node, String help) {
|
||||
return new GameModeConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
// Location
|
||||
/**
|
||||
* Constructs a new LocationConfigProperty.
|
||||
*
|
||||
* @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 LocationConfigProperty getNewProperty(String name, Location defaultValue, String help) {
|
||||
return new LocationConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public LocationConfigProperty getNewProperty(String name, Location defaultValue, String node, String help) {
|
||||
return new LocationConfigProperty(this.section, name, defaultValue, node, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigProperty.
|
||||
*
|
||||
* @param name The name of this ConfigProperty.
|
||||
* @param defaultValue The default-value.
|
||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
||||
* @param help The text that's displayed when a user failed to set the property.
|
||||
* @param method The name of the method that's used to set this property.
|
||||
* @return The ConfigProperty.
|
||||
*/
|
||||
public LocationConfigProperty getNewProperty(String name, Location defaultValue, String node, String help, String method) {
|
||||
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
|
||||
*
|
||||
* This property will execute 'method' after it has been successfully set.
|
||||
* This string will NOT be saved to the config file.
|
||||
*
|
||||
* @param name The name of this ConifgProperty
|
||||
* @param defaultValue The default value.
|
||||
* @param help What string is shown for help.
|
||||
* @param method The method that should be executed.
|
||||
* @param saveToConfig Should the variable save to the config?
|
||||
* @return The ActiveStringConfigProperty
|
||||
*/
|
||||
public ActiveStringConfigProperty getNewProperty(String name, String defaultValue, String help, String method, boolean saveToConfig) {
|
||||
return new ActiveStringConfigProperty(name, defaultValue, help, method);
|
||||
}
|
||||
}
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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 org.bukkit.Difficulty;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link Difficulty} config-property.
|
||||
*/
|
||||
public class DifficultyConfigProperty implements MVActiveConfigProperty<Difficulty> {
|
||||
private String name;
|
||||
private Difficulty value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
|
||||
public DifficultyConfigProperty(ConfigurationSection section, String name, Difficulty defaultValue, String help) {
|
||||
this(section, name, defaultValue, name, help);
|
||||
}
|
||||
|
||||
public DifficultyConfigProperty(ConfigurationSection section, String name, Difficulty 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 Difficulty getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(Difficulty 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(Difficulty.getByValue(Integer.parseInt(value)));
|
||||
} catch (NumberFormatException nfe) {
|
||||
try {
|
||||
return this.setValue(Difficulty.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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the method that will be executed.
|
||||
*
|
||||
* @return The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return "setActualDifficulty";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method that will be executed.
|
||||
*
|
||||
* @param methodName The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public void setMethod(String methodName) {
|
||||
// Unused here. This will only ever be setDifficulty.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getPropertyClass() {
|
||||
return Difficulty.class;
|
||||
}
|
||||
}
|
||||
-133
@@ -1,133 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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 org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link Double} config-property.
|
||||
*/
|
||||
public class DoubleConfigProperty implements MVActiveConfigProperty<Double> {
|
||||
private String name;
|
||||
private Double value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
private String method;
|
||||
|
||||
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String help) {
|
||||
this(section, name, defaultValue, name, help);
|
||||
}
|
||||
|
||||
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.value = defaultValue;
|
||||
this.setValue(this.section.getDouble(this.configNode, defaultValue));
|
||||
}
|
||||
|
||||
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String configNode, String help, String method) {
|
||||
this(section, name, defaultValue, configNode, help);
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Double getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(Double value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
this.section.set(configNode, this.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean parseValue(String value) {
|
||||
try {
|
||||
this.setValue(Double.parseDouble(value));
|
||||
return true;
|
||||
} catch (NumberFormatException 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the method that will be executed.
|
||||
*
|
||||
* @return The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method that will be executed.
|
||||
*
|
||||
* @param methodName The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public void setMethod(String methodName) {
|
||||
this.method = methodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class of the object we're looking at.
|
||||
*
|
||||
* @return the class of the object we're looking at.
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getPropertyClass() {
|
||||
return Double.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
|
||||
/**
|
||||
* Entryfee-settings.
|
||||
*/
|
||||
@SerializableAs("MVEntryFee")
|
||||
public class EntryFee extends SerializationConfig {
|
||||
@Property
|
||||
private double amount;
|
||||
@Property
|
||||
private int currency;
|
||||
|
||||
public EntryFee() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EntryFee(Map<String, Object> values) {
|
||||
super(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void setDefaults() {
|
||||
amount = 0D;
|
||||
currency = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount
|
||||
*/
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the currency
|
||||
*/
|
||||
public int getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount.
|
||||
* @param amount The new value.
|
||||
*/
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the currency.
|
||||
* @param currency The new value.
|
||||
*/
|
||||
public void setCurrency(int currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
}
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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 org.bukkit.GameMode;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link GameMode} config-property.
|
||||
*/
|
||||
public class GameModeConfigProperty implements MVActiveConfigProperty<GameMode> {
|
||||
private String name;
|
||||
private GameMode value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
|
||||
public GameModeConfigProperty(ConfigurationSection section, String name, GameMode defaultValue, String help) {
|
||||
this(section, name, defaultValue, name, help);
|
||||
}
|
||||
|
||||
public GameModeConfigProperty(ConfigurationSection section, String name, GameMode 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 GameMode getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(GameMode 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(GameMode.getByValue(Integer.parseInt(value)));
|
||||
} catch (NumberFormatException nfe) {
|
||||
try {
|
||||
return this.setValue(GameMode.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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the method that will be executed.
|
||||
*
|
||||
* @return The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return "setActualGameMode";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method that will be executed.
|
||||
*
|
||||
* @param methodName The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public void setMethod(String methodName) {
|
||||
// Not required. Gamemode will only ever be one.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getPropertyClass() {
|
||||
return GameMode.class;
|
||||
}
|
||||
}
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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 org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link Integer} config-property.
|
||||
*/
|
||||
public class IntegerConfigProperty implements MVConfigProperty<Integer> {
|
||||
private String name;
|
||||
private Integer value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
|
||||
public IntegerConfigProperty(ConfigurationSection section, String name, Integer defaultValue, String help) {
|
||||
this(section, name, defaultValue, name, help);
|
||||
}
|
||||
|
||||
public IntegerConfigProperty(ConfigurationSection section, String name, Integer defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.value = defaultValue;
|
||||
this.setValue(this.section.getInt(this.configNode, defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(Integer value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
this.section.set(configNode, this.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean parseValue(String value) {
|
||||
try {
|
||||
this.setValue(Integer.parseInt(value));
|
||||
return true;
|
||||
} catch (NumberFormatException 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();
|
||||
}
|
||||
}
|
||||
-154
@@ -1,154 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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.utils.LocationManipulation;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link Location} config-property.
|
||||
*/
|
||||
public class LocationConfigProperty implements MVActiveConfigProperty<Location> {
|
||||
private String name;
|
||||
private Location value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
private String method;
|
||||
|
||||
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String help) {
|
||||
this(section, name, defaultValue, name, help);
|
||||
}
|
||||
|
||||
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.value = defaultValue;
|
||||
this.setValue(this.getLocationFromConfig(defaultValue));
|
||||
}
|
||||
|
||||
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help, String method) {
|
||||
this(section, name, defaultValue, configNode, help);
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean parseValue(String value) {
|
||||
// TODO: oh my god, what should we do here?
|
||||
Location parsed = LocationManipulation.stringToLocation(value);
|
||||
return this.setValue(parsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getConfigNode() {
|
||||
return this.configNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(Location value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
this.section.set(configNode + ".x", this.value.getX());
|
||||
this.section.set(configNode + ".y", this.value.getY());
|
||||
this.section.set(configNode + ".z", this.value.getZ());
|
||||
this.section.set(configNode + ".pitch", this.value.getPitch());
|
||||
this.section.set(configNode + ".yaw", this.value.getYaw());
|
||||
this.section.set(configNode + ".world", this.value.getWorld().getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Location getLocationFromConfig(Location defaultValue) {
|
||||
double x = this.section.getDouble(this.configNode + ".x", defaultValue.getX());
|
||||
double y = this.section.getDouble(this.configNode + ".y", defaultValue.getY());
|
||||
double z = this.section.getDouble(this.configNode + ".z", defaultValue.getZ());
|
||||
double pitch = this.section.getDouble(this.configNode + ".pitch", defaultValue.getPitch());
|
||||
double yaw = this.section.getDouble(this.configNode + ".yaw", defaultValue.getYaw());
|
||||
String w = this.section.getString(this.configNode + ".world", defaultValue.getWorld().getName());
|
||||
Location found = LocationManipulation.stringToLocation(w + ":" + x + "," + y + "," + z + ":" + yaw + ":" + pitch);
|
||||
// TODO: oh my god, what should we do here?
|
||||
if (found != null) {
|
||||
return found;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO: oh my god, what should we do here?
|
||||
return LocationManipulation.strCoordsRaw(this.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the method that will be executed.
|
||||
*
|
||||
* @return The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method that will be executed.
|
||||
*
|
||||
* @param methodName The name of the method in MVWorld to be called.
|
||||
*/
|
||||
@Override
|
||||
public void setMethod(String methodName) {
|
||||
this.method = methodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class of the object we're looking at.
|
||||
*
|
||||
* @return the class of the object we're looking at.
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getPropertyClass() {
|
||||
return Location.class;
|
||||
}
|
||||
}
|
||||
+2
@@ -10,8 +10,10 @@ package com.onarandombox.MultiverseCore.configuration;
|
||||
/**
|
||||
* An "active" {@link MVConfigProperty} that uses the specified method to be "actually" set.
|
||||
* @param <T> The type of the config-property.
|
||||
* @deprecated This is deprecated.
|
||||
* @see MVConfigProperty
|
||||
*/
|
||||
@Deprecated
|
||||
public interface MVActiveConfigProperty<T> extends MVConfigProperty<T> {
|
||||
/**
|
||||
* Gets the method that will be executed.
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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.api.LoggablePlugin;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/*
|
||||
* This is a mess, so I'm just going to suppress all warnings here.
|
||||
* BEGIN CHECKSTYLE-SUPPRESSION: ALL
|
||||
*/
|
||||
|
||||
/**
|
||||
* This will be gone in 2.4.
|
||||
* @deprecated This isn't used any more, is it? No. No it is not.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class MVConfigMigrator {
|
||||
|
||||
public List<String> createdDefaults = new ArrayList<String>();
|
||||
|
||||
public abstract boolean migrate(String name, File folder);
|
||||
|
||||
protected final void migrateListItem(Configuration newConfig, Configuration oldConfig, String key, String oldProperty, String newProperty) {
|
||||
List<String> list = Arrays.asList(oldConfig.getString("worlds." + key + oldProperty).split(","));
|
||||
if (list.size() > 0) {
|
||||
if (list.get(0).length() == 0) {
|
||||
list = new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
newConfig.setProperty("worlds." + key + newProperty, list);
|
||||
}
|
||||
|
||||
protected final File detectMultiverseFolders(File folder, LoggablePlugin mvPlugin) {
|
||||
File oldFolder = null;
|
||||
mvPlugin.log(Level.INFO, "Starting Multiverse Configuration Migrator(MVCM)!");
|
||||
// They still have MV 1 installed! Good!
|
||||
if (mvPlugin.getServer().getPluginManager().getPlugin("MultiVerse") != null) {
|
||||
mvPlugin.log(Level.INFO, "Found MultiVerse 1. Starting Config Migration...");
|
||||
Plugin plugin = mvPlugin.getServer().getPluginManager().getPlugin("MultiVerse");
|
||||
oldFolder = plugin.getDataFolder();
|
||||
} else {
|
||||
// They didn't have MV 1 enabled... let's try and find the folder...
|
||||
File[] folders = folder.getParentFile().listFiles();
|
||||
List<File> folderList = Arrays.asList(folders);
|
||||
for (File f : folderList) {
|
||||
if (f.getName().equalsIgnoreCase("MultiVerse")) {
|
||||
mvPlugin.log(Level.INFO, "Found the MultiVerse 1 config folder. Starting Config Migration...");
|
||||
oldFolder = f;
|
||||
}
|
||||
}
|
||||
if (oldFolder == null) {
|
||||
mvPlugin.log(Level.INFO, "Did not find the MV1 Folder. If you did not have MultiVerse 1 installed and this is the FIRST time you're running MV2, this message is GOOD. ");
|
||||
mvPlugin.log(Level.INFO, "If you did, your configs were **NOT** migrated! Go Here: INSERTURLFORHELP");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return oldFolder;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* END CHECKSTYLE-SUPPRESSION: ALL
|
||||
*/
|
||||
@@ -11,7 +11,9 @@ package com.onarandombox.MultiverseCore.configuration;
|
||||
* A generic config-property.
|
||||
*
|
||||
* @param <T> The type of the config-property.
|
||||
* @deprecated This is deprecated.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface MVConfigProperty<T> {
|
||||
/**
|
||||
* Gets the name of this property.
|
||||
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link AllowedPortalType} 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,98 @@
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
|
||||
/**
|
||||
* Just like a regular {@link Location}, however {@code world} is usually {@code null}
|
||||
* or just a weak reference and it implements {@link ConfigurationSerializable}.
|
||||
*/
|
||||
@SerializableAs("MVSpawnLocation")
|
||||
public class SpawnLocation extends Location implements ConfigurationSerializable {
|
||||
private Reference<World> worldRef;
|
||||
|
||||
public SpawnLocation(double x, double y, double z) {
|
||||
super(null, x, y, z);
|
||||
}
|
||||
|
||||
public SpawnLocation(double x, double y, double z, float yaw, float pitch) {
|
||||
super(null, x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
public SpawnLocation(Location loc) {
|
||||
this(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return (this.worldRef != null) ? this.worldRef.get() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setWorld(World world) {
|
||||
this.worldRef = new WeakReference<World>(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Chunk getChunk() {
|
||||
if ((this.worldRef != null) && (this.worldRef.get() != null))
|
||||
return this.worldRef.get().getChunkAt(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getBlock() {
|
||||
if ((this.worldRef != null) && (this.worldRef.get() != null))
|
||||
return this.worldRef.get().getBlockAt(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> serialized = new HashMap<String, Object>(5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
serialized.put("x", this.getX());
|
||||
serialized.put("y", this.getY());
|
||||
serialized.put("z", this.getZ());
|
||||
serialized.put("pitch", this.getPitch());
|
||||
serialized.put("yaw", this.getYaw());
|
||||
return serialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Let Bukkit be able to deserialize this.
|
||||
* @param args The map.
|
||||
* @return The deserialized object.
|
||||
*/
|
||||
public static SpawnLocation deserialize(Map<String, Object> args) {
|
||||
double x = ((Number) args.get("x")).doubleValue();
|
||||
double y = ((Number) args.get("y")).doubleValue();
|
||||
double z = ((Number) args.get("z")).doubleValue();
|
||||
float pitch = ((Number) args.get("pitch")).floatValue();
|
||||
float yaw = ((Number) args.get("yaw")).floatValue();
|
||||
return new SpawnLocation(x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
|
||||
/**
|
||||
* Spawning-Settings.
|
||||
*/
|
||||
@SerializableAs("MVSpawnSettings")
|
||||
public class SpawnSettings extends SerializationConfig {
|
||||
@Property
|
||||
private SubSpawnSettings animals;
|
||||
@Property
|
||||
private SubSpawnSettings monsters;
|
||||
|
||||
public SpawnSettings() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SpawnSettings(Map<String, Object> values) {
|
||||
super(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDefaults() {
|
||||
animals = new SubSpawnSettings();
|
||||
monsters = new SubSpawnSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the animal-settings
|
||||
*/
|
||||
public SubSpawnSettings getAnimalSettings() {
|
||||
return animals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the monster-settings
|
||||
*/
|
||||
public SubSpawnSettings getMonsterSettings() {
|
||||
return monsters;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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 org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* A {@link String} config-property.
|
||||
*/
|
||||
public class StringConfigProperty implements MVConfigProperty<String> {
|
||||
private String name;
|
||||
private String value;
|
||||
private String configNode;
|
||||
private ConfigurationSection section;
|
||||
private String help;
|
||||
|
||||
public StringConfigProperty(ConfigurationSection section, String name, String defaultValue, String help) {
|
||||
this(section, name, defaultValue, defaultValue, help);
|
||||
}
|
||||
|
||||
public StringConfigProperty(ConfigurationSection section, String name, String 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean parseValue(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.setValue(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getConfigNode() {
|
||||
return this.configNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setValue(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
this.section.set(configNode, this.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
|
||||
/**
|
||||
* SpawnSubSettings.
|
||||
*/
|
||||
@SerializableAs("MVSpawnSubSettings")
|
||||
public class SubSpawnSettings extends SerializationConfig {
|
||||
@Property
|
||||
private boolean spawn;
|
||||
@Property
|
||||
private List<String> exceptions;
|
||||
|
||||
public SubSpawnSettings() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SubSpawnSettings(Map<String, Object> values) {
|
||||
super(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDefaults() {
|
||||
spawn = true;
|
||||
exceptions = new ArrayList<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return spawn
|
||||
*/
|
||||
public boolean doSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param spawn The new value.
|
||||
*/
|
||||
public void setSpawn(boolean spawn) {
|
||||
this.spawn = spawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the exceptions
|
||||
*/
|
||||
public List<String> getExceptions() {
|
||||
return exceptions;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent;
|
||||
|
||||
import me.main__.util.SerializationConfig.ChangeDeniedException;
|
||||
import me.main__.util.SerializationConfig.ObjectUsingValidator;
|
||||
|
||||
/**
|
||||
* Validates world-property-changes.
|
||||
* @param <T> The type of the property that should be validated.
|
||||
*/
|
||||
public class WorldPropertyValidator<T> extends ObjectUsingValidator<T, MVWorld> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public T validateChange(String property, T newValue, T oldValue, MVWorld object) throws ChangeDeniedException {
|
||||
MVWorldPropertyChangeEvent<T> event = new MVWorldPropertyChangeEvent<T>(object, null, property, newValue);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled())
|
||||
throw new ChangeDeniedException();
|
||||
return event.getTheNewValue();
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class DestinationFactory {
|
||||
Class<? extends MVDestination> myClass = this.destList.get(idenChar);
|
||||
try {
|
||||
MVDestination mydest = myClass.newInstance();
|
||||
if (!mydest.isThisType((MultiverseCore) this.plugin, destination)) {
|
||||
if (!mydest.isThisType(this.plugin, destination)) {
|
||||
return new InvalidDestination();
|
||||
}
|
||||
mydest.setDestination(this.plugin, destination);
|
||||
|
||||
@@ -70,7 +70,7 @@ public class WorldDestination implements MVDestination {
|
||||
return spawnLoc;
|
||||
}
|
||||
|
||||
private Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) {
|
||||
private static Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) {
|
||||
if (world != null) {
|
||||
return world.getSpawnLocation();
|
||||
} else {
|
||||
@@ -115,7 +115,6 @@ public class WorldDestination implements MVDestination {
|
||||
this.world = ((MultiverseCore) plugin).getMVWorldManager().getMVWorld(items[1]);
|
||||
isValid = true;
|
||||
if (items.length == 3) {
|
||||
// TODO: oh my god, what should we do here?
|
||||
this.yaw = core.getLocationManipulation().getYaw(items[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,49 +11,33 @@ import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* A regular {@link ChatColor} represented by an english string.
|
||||
* @see ChatColor
|
||||
*/
|
||||
public enum EnglishChatColor {
|
||||
/*
|
||||
* I know. this is quite ugly.
|
||||
*/
|
||||
/** AQUA. */
|
||||
AQUA("AQUA", ChatColor.AQUA),
|
||||
/** BLACK. */
|
||||
BLACK("BLACK", ChatColor.BLACK),
|
||||
/** BLUE. */
|
||||
BLUE("BLUE", ChatColor.BLUE),
|
||||
/** DARKAQUA. */
|
||||
DARKAQUA("DARKAQUA", ChatColor.DARK_AQUA),
|
||||
/** DARKBLUE. */
|
||||
DARKBLUE("DARKBLUE", ChatColor.DARK_BLUE),
|
||||
/** DARKGRAY. */
|
||||
DARKGRAY("DARKGRAY", ChatColor.DARK_GRAY),
|
||||
/** DARKGREEN. */
|
||||
DARKGREEN("DARKGREEN", ChatColor.DARK_GREEN),
|
||||
/** DARKPURPLE. */
|
||||
DARKPURPLE("DARKPURPLE", ChatColor.DARK_PURPLE),
|
||||
/** DARKRED. */
|
||||
DARKRED("DARKRED", ChatColor.DARK_RED),
|
||||
/** GOLD. */
|
||||
GOLD("GOLD", ChatColor.GOLD),
|
||||
/** GRAY. */
|
||||
GRAY("GRAY", ChatColor.GRAY),
|
||||
/** GREEN. */
|
||||
GREEN("GREEN", ChatColor.GREEN),
|
||||
/** LIGHTPURPLE. */
|
||||
LIGHTPURPLE("LIGHTPURPLE", ChatColor.LIGHT_PURPLE),
|
||||
/** RED. */
|
||||
RED("RED", ChatColor.RED),
|
||||
/** YELLOW. */
|
||||
YELLOW("YELLOW", ChatColor.YELLOW),
|
||||
/** WHITE. */
|
||||
WHITE("WHITE", ChatColor.WHITE);
|
||||
private ChatColor color;
|
||||
private String text;
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
AQUA(ChatColor.AQUA),
|
||||
BLACK(ChatColor.BLACK),
|
||||
BLUE(ChatColor.BLUE),
|
||||
DARKAQUA(ChatColor.DARK_AQUA),
|
||||
DARKBLUE(ChatColor.DARK_BLUE),
|
||||
DARKGRAY(ChatColor.DARK_GRAY),
|
||||
DARKGREEN(ChatColor.DARK_GREEN),
|
||||
DARKPURPLE(ChatColor.DARK_PURPLE),
|
||||
DARKRED(ChatColor.DARK_RED),
|
||||
GOLD(ChatColor.GOLD),
|
||||
GRAY(ChatColor.GRAY),
|
||||
GREEN(ChatColor.GREEN),
|
||||
LIGHTPURPLE(ChatColor.LIGHT_PURPLE),
|
||||
RED(ChatColor.RED),
|
||||
YELLOW(ChatColor.YELLOW),
|
||||
WHITE(ChatColor.WHITE);
|
||||
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
|
||||
EnglishChatColor(String name, ChatColor color) {
|
||||
private final ChatColor color;
|
||||
//private final String text;
|
||||
|
||||
EnglishChatColor(ChatColor color) {
|
||||
this.color = color;
|
||||
this.text = name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +45,7 @@ public enum EnglishChatColor {
|
||||
* @return The text.
|
||||
*/
|
||||
public String getText() {
|
||||
return this.text;
|
||||
return this.name();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,11 +76,20 @@ public enum EnglishChatColor {
|
||||
public static EnglishChatColor fromString(String text) {
|
||||
if (text != null) {
|
||||
for (EnglishChatColor c : EnglishChatColor.values()) {
|
||||
if (text.equalsIgnoreCase(c.text)) {
|
||||
if (text.equalsIgnoreCase(c.name())) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks if the given-color name is a valid color.
|
||||
* @param aliasColor A color-name.
|
||||
* @return True if the name is a valid color, false if it isn't.
|
||||
*/
|
||||
public static boolean isValidAliasColor(String aliasColor) {
|
||||
return (EnglishChatColor.fromString(aliasColor) != null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* A regular {@link ChatColor} represented by an english string.
|
||||
* @see ChatColor
|
||||
*/
|
||||
public enum EnglishChatStyle {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
/** No style. */
|
||||
NORMAL(null),
|
||||
MAGIC(ChatColor.MAGIC),
|
||||
BOLD(ChatColor.BOLD),
|
||||
STRIKETHROUGH(ChatColor.STRIKETHROUGH),
|
||||
UNDERLINE(ChatColor.UNDERLINE),
|
||||
ITALIC(ChatColor.ITALIC);
|
||||
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
|
||||
private final ChatColor color;
|
||||
|
||||
EnglishChatStyle(ChatColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color.
|
||||
* @return The color as {@link ChatColor}.
|
||||
*/
|
||||
public ChatColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an {@link EnglishChatStyle} from a {@link String}.
|
||||
* @param text The {@link String}.
|
||||
* @return The {@link EnglishChatStyle}.
|
||||
*/
|
||||
public static EnglishChatStyle fromString(String text) {
|
||||
if (text != null) {
|
||||
for (EnglishChatStyle c : EnglishChatStyle.values()) {
|
||||
if (text.equalsIgnoreCase(c.name())) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,9 @@ import java.util.List;
|
||||
* Called when the Multiverse-config should be reloaded.
|
||||
*/
|
||||
public class MVConfigReloadEvent extends Event {
|
||||
private static final long serialVersionUID = 3647950355746345397L;
|
||||
private List<String> configsLoaded;
|
||||
|
||||
public MVConfigReloadEvent(List<String> configsLoaded) {
|
||||
super("MVConfigReload");
|
||||
this.configsLoaded = configsLoaded;
|
||||
}
|
||||
|
||||
|
||||
+21
-1
@@ -20,9 +20,9 @@ public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
|
||||
private Player p;
|
||||
private Location l;
|
||||
private boolean isCancelled;
|
||||
private boolean canUse = true;
|
||||
|
||||
public MVPlayerTouchedPortalEvent(Player p, Location l) {
|
||||
super("MVPlayerTouchedPortalEvent");
|
||||
this.p = p;
|
||||
this.l = l;
|
||||
}
|
||||
@@ -61,6 +61,26 @@ public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
|
||||
return this.p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not the player in this event can use this portal.
|
||||
*
|
||||
* @return True if the player can use this portal.
|
||||
*/
|
||||
public boolean canUseThisPortal() {
|
||||
return this.canUse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not the player in this event can use this portal.
|
||||
* <p>
|
||||
* Setting this to false will cause the player to bounce back!
|
||||
*
|
||||
* @param canUse Whether or not the user can go through this portal.
|
||||
*/
|
||||
public void setCanUseThisPortal(boolean canUse) {
|
||||
this.canUse = canUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.isCancelled;
|
||||
|
||||
@@ -22,7 +22,6 @@ public class MVRespawnEvent extends Event {
|
||||
|
||||
|
||||
public MVRespawnEvent(Location spawningAt, Player p, String respawnMethod) {
|
||||
super("MVRespawn");
|
||||
this.player = p;
|
||||
this.location = spawningAt;
|
||||
this.respawnMethod = respawnMethod;
|
||||
|
||||
@@ -28,7 +28,6 @@ public class MVTeleportEvent extends Event implements Cancellable {
|
||||
private boolean isCancelled;
|
||||
|
||||
public MVTeleportEvent(MVDestination dest, Player teleportee, CommandSender teleporter, boolean safeTeleport) {
|
||||
super("SafeTTeleporter");
|
||||
this.teleportee = teleportee;
|
||||
this.teleporter = teleporter;
|
||||
this.dest = dest;
|
||||
|
||||
@@ -11,8 +11,7 @@ public class MVVersionEvent extends Event {
|
||||
private final StringBuilder versionInfoBuilder;
|
||||
|
||||
public MVVersionEvent(String versionInfo) {
|
||||
super("MVVersionEvent");
|
||||
versionInfoBuilder = new StringBuilder(versionInfo);
|
||||
this.versionInfoBuilder = new StringBuilder(versionInfo);
|
||||
}
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@@ -38,7 +37,7 @@ public class MVVersionEvent extends Event {
|
||||
* @return The version-info.
|
||||
*/
|
||||
public String getVersionInfo() {
|
||||
return versionInfoBuilder.toString();
|
||||
return this.versionInfoBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +45,6 @@ public class MVVersionEvent extends Event {
|
||||
* @param moreVersionInfo The version-info to add. Should end with '\n'.
|
||||
*/
|
||||
public void appendVersionInfo(String moreVersionInfo) {
|
||||
versionInfoBuilder.append(moreVersionInfo);
|
||||
this.versionInfoBuilder.append(moreVersionInfo);
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,6 @@ public class MVWorldDeleteEvent extends Event implements Cancellable {
|
||||
private final boolean removeFromConfig;
|
||||
|
||||
public MVWorldDeleteEvent(MultiverseWorld world, boolean removeFromConfig) {
|
||||
super("MVWorldDeleteEvent");
|
||||
|
||||
if (world == null)
|
||||
throw new IllegalArgumentException("world can't be null!");
|
||||
|
||||
|
||||
+30
-5
@@ -19,17 +19,18 @@ import org.bukkit.event.HandlerList;
|
||||
* If it is cancelled, no change will happen.
|
||||
* <p>
|
||||
* If you want to get the values of the world before the change, query the world.
|
||||
* If you want to get the value being changed, use getProperty()
|
||||
* To get the name of the property that was changed, use {@link #getPropertyName()}.
|
||||
* To get the new value, use {@link #getTheNewValue()}. To change it, use {@link #setTheNewValue(Object)}.
|
||||
* @param <T> The type of the property that was set.
|
||||
*/
|
||||
public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
||||
public class MVWorldPropertyChangeEvent<T> extends Event implements Cancellable {
|
||||
private MultiverseWorld world;
|
||||
private CommandSender changer;
|
||||
private boolean isCancelled = false;
|
||||
private String value;
|
||||
private String name;
|
||||
private T value;
|
||||
|
||||
public MVWorldPropertyChangeEvent(MultiverseWorld world, CommandSender changer, String name, String value) {
|
||||
super("MVWorldPropertyChange");
|
||||
public MVWorldPropertyChangeEvent(MultiverseWorld world, CommandSender changer, String name, T value) {
|
||||
this.world = world;
|
||||
this.changer = changer;
|
||||
this.name = name;
|
||||
@@ -65,16 +66,38 @@ public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
||||
/**
|
||||
* Gets the new value.
|
||||
* @return The new value.
|
||||
* @deprecated Use {@link #getTheNewValue()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getNewValue() {
|
||||
return this.value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new value.
|
||||
* @return The new value.
|
||||
*/
|
||||
public T getTheNewValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new value.
|
||||
* <p>
|
||||
* This method is only a stub, it'll <b>always</b> throw an {@link UnsupportedOperationException}!
|
||||
* @param value The new new value.
|
||||
* @deprecated Use {@link #setTheNewValue(Object)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setNewValue(String value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new value.
|
||||
* @param value The new value.
|
||||
*/
|
||||
public void setTheNewValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -89,6 +112,8 @@ public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Gets the person (or console) who was responsible for the change.
|
||||
* <p>
|
||||
* This may be null!
|
||||
*
|
||||
* @return The person (or console) who was responsible for the change.
|
||||
*/
|
||||
|
||||
+4
@@ -14,4 +14,8 @@ public class PropertyDoesNotExistException extends Exception {
|
||||
public PropertyDoesNotExistException(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public PropertyDoesNotExistException(String name, Throwable cause) {
|
||||
super(name, cause);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -86,8 +86,8 @@ public class MVEntityListener implements Listener {
|
||||
@EventHandler
|
||||
public void creatureSpawn(CreatureSpawnEvent event) {
|
||||
// Check to see if the Creature is spawned by a plugin, we don't want to prevent this behaviour.
|
||||
// TODO: Implement MONSTER_EGG when it becomes available.
|
||||
if (event.getSpawnReason() == SpawnReason.CUSTOM) {
|
||||
// TODO: Allow the egg thing to be a config param. Doubt this will be per world; seems silly.
|
||||
if (event.getSpawnReason() == SpawnReason.CUSTOM || event.getSpawnReason() == SpawnReason.SPAWNER_EGG) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,14 +99,13 @@ public class MVEntityListener implements Listener {
|
||||
if (!(this.worldManager.isMVWorld(world.getName())))
|
||||
return;
|
||||
|
||||
CreatureType creature = event.getCreatureType();
|
||||
|
||||
EntityType type = event.getEntityType();
|
||||
MultiverseWorld mvworld = this.worldManager.getMVWorld(world.getName());
|
||||
|
||||
/**
|
||||
* Handle people with non-standard animals: ie a patched craftbukkit.
|
||||
*/
|
||||
if (creature == null) {
|
||||
if (type == null || type.getName() == null) {
|
||||
this.plugin.log(Level.FINER, "Found a null typed creature.");
|
||||
return;
|
||||
}
|
||||
@@ -114,18 +113,18 @@ public class MVEntityListener implements Listener {
|
||||
/**
|
||||
* Animal Handling
|
||||
*/
|
||||
if (event.getEntity() instanceof Animals || event.getEntity() instanceof Squid) {
|
||||
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getAnimalList(), mvworld.canAnimalsSpawn(), creature.toString().toUpperCase()));
|
||||
if (!event.isCancelled() && (event.getEntity() instanceof Animals || event.getEntity() instanceof Squid)) {
|
||||
event.setCancelled(shouldWeKillThisCreature(mvworld.getAnimalList(), mvworld.canAnimalsSpawn(), type.getName().toUpperCase()));
|
||||
}
|
||||
/**
|
||||
* Monster Handling
|
||||
*/
|
||||
if (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof Slime) {
|
||||
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.canMonstersSpawn(), creature.toString().toUpperCase()));
|
||||
if (!event.isCancelled() && (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof Slime)) {
|
||||
event.setCancelled(shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.canMonstersSpawn(), type.getName().toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldWeKillThisCreature(List<String> creatureList, boolean allowCreatureSpawning, String creature) {
|
||||
private static boolean shouldWeKillThisCreature(List<String> creatureList, boolean allowCreatureSpawning, String creature) {
|
||||
if (creatureList.isEmpty() && allowCreatureSpawning) {
|
||||
// 1. There are no exceptions and animals are allowed. Save it.
|
||||
return false;
|
||||
|
||||
@@ -126,14 +126,20 @@ public class MVPlayerListener implements Listener {
|
||||
public void playerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (!p.hasPlayedBefore()) {
|
||||
this.plugin.log(Level.FINE, "Player joined first!");
|
||||
this.plugin.log(Level.FINER, "Player joined for the FIRST time!");
|
||||
if (plugin.getMVConfig().getFirstSpawnOverride()) {
|
||||
this.plugin.log(Level.FINE, "Moving NEW player to(firstspawnoverride): " + worldManager.getFirstSpawnWorld().getSpawnLocation());
|
||||
this.spawnNewPlayer(p);
|
||||
this.plugin.log(Level.FINE, "Moving NEW player to(firstspawnoverride): "
|
||||
+ worldManager.getFirstSpawnWorld().getSpawnLocation());
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player joined AGAIN!");
|
||||
this.plugin.log(Level.FINER, "Player joined AGAIN!");
|
||||
if (this.plugin.getMVConfig().getEnforceAccess() // check this only if we're enforcing access!
|
||||
&& !this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) {
|
||||
p.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
}
|
||||
}
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
@@ -164,8 +170,8 @@ public class MVPlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void playerTeleport(PlayerTeleportEvent event) {
|
||||
this.plugin.log(Level.FINEST, "Got teleport event for player '" + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'");
|
||||
|
||||
this.plugin.log(Level.FINER, "Got teleport event for player '"
|
||||
+ event.getPlayer().getName() + "' with cause '" + event.getCause() + "'");
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
@@ -174,41 +180,55 @@ public class MVPlayerListener implements Listener {
|
||||
String teleporterName = MultiverseCore.getPlayerTeleporter(teleportee.getName());
|
||||
if (teleporterName != null) {
|
||||
if (teleporterName.equals("CONSOLE")) {
|
||||
this.plugin.log(Level.FINEST, "We know the teleporter is the console! Magical!");
|
||||
this.plugin.log(Level.FINER, "We know the teleporter is the console! Magical!");
|
||||
teleporter = this.plugin.getServer().getConsoleSender();
|
||||
} else {
|
||||
teleporter = this.plugin.getServer().getPlayer(teleporterName);
|
||||
}
|
||||
}
|
||||
this.plugin.log(Level.FINEST, String.format("Inferred sender '%s' from name '%s', fetched from name '%s'",
|
||||
teleporter, teleporterName, teleportee.getName()));
|
||||
this.plugin.log(Level.FINER, "Inferred sender '" + teleporter + "' from name '"
|
||||
+ teleporterName + "', fetched from name '" + teleportee.getName() + "'");
|
||||
MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
|
||||
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
|
||||
if (fromWorld == null || toWorld == null)
|
||||
return;
|
||||
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
|
||||
// The player is Teleporting to the same world.
|
||||
this.plugin.log(Level.FINER, "Player '" + teleportee.getName() + "' is teleporting to the same world.");
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
return;
|
||||
}
|
||||
// TODO: Refactor these lines.
|
||||
// Charge the teleporter
|
||||
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true));
|
||||
if (event.isCancelled() && teleporter != null) {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because '%s' don't have the FUNDS required to enter it.",
|
||||
teleportee.getName(), event.getTo().getWorld().getName(), teleporter.getName()));
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
|
||||
+ "' because '" + teleporter.getName()
|
||||
+ "' don't have the FUNDS required to enter it.");
|
||||
return;
|
||||
}
|
||||
if (plugin.getMVConfig().getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
|
||||
if (event.isCancelled() && teleporter != null) {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because '%s' don't have: multiverse.access.%s",
|
||||
teleportee.getName(), event.getTo().getWorld().getName(), teleporter.getName(), event.getTo().getWorld().getName()));
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
|
||||
+ "' because '" + teleporter.getName()
|
||||
+ "' don't have: multiverse.access." + event.getTo().getWorld().getName());
|
||||
} else {
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
}
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was allowed to go to '%s' because enforceaccess is off.",
|
||||
teleportee.getName(), event.getTo().getWorld().getName()));
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
+ "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off.");
|
||||
}
|
||||
}
|
||||
|
||||
private void stateSuccess(String playerName, String worldName) {
|
||||
this.plugin.log(Level.FINE, "MV-Core is allowing Player '" + playerName
|
||||
+ "' to go to '" + worldName + "'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to adjust the portal location to the actual portal location (and not
|
||||
* right outside of it.
|
||||
@@ -216,7 +236,6 @@ public class MVPlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void playerPortalCheck(PlayerPortalEvent event) {
|
||||
this.plugin.log(Level.FINE, "CALLING CORE-ADJUST!!!");
|
||||
if (event.isCancelled() || event.getFrom() == null) {
|
||||
return;
|
||||
}
|
||||
@@ -258,24 +277,27 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true));
|
||||
if (event.isCancelled()) {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have the FUNDS required to enter.",
|
||||
event.getPlayer().getName(), event.getTo().getWorld().getName()));
|
||||
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
|
||||
+ "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
|
||||
+ "' because they don't have the FUNDS required to enter.");
|
||||
return;
|
||||
}
|
||||
if (plugin.getMVConfig().getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer()));
|
||||
if (event.isCancelled()) {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have: multiverse.access.%s",
|
||||
event.getPlayer().getName(), event.getTo().getWorld().getName(), event.getTo().getWorld().getName()));
|
||||
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
|
||||
+ "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
|
||||
+ "' because they don't have: multiverse.access." + event.getTo().getWorld().getName());
|
||||
}
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was allowed to go to '%s' because enforceaccess is off.",
|
||||
event.getPlayer().getName(), event.getTo().getWorld().getName()));
|
||||
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
|
||||
+ "' was allowed to go to '" + event.getTo().getWorld().getName()
|
||||
+ "' because enforceaccess is off.");
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnNewPlayer(final Player player) {
|
||||
// Spawn the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
|
||||
private void sendPlayerToDefaultWorld(final Player player) {
|
||||
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
@@ -290,6 +312,9 @@ public class MVPlayerListener implements Listener {
|
||||
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
|
||||
if (mvWorld != null) {
|
||||
this.handleGameMode(player, mvWorld);
|
||||
} else {
|
||||
this.plugin.log(Level.FINER, "Not handling gamemode for world '" + world.getName()
|
||||
+ "' not managed by Multiverse.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,20 +327,21 @@ public class MVPlayerListener implements Listener {
|
||||
// We perform this task one tick later to MAKE SURE that the player actually reaches the
|
||||
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
|
||||
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
||||
this.plugin.log(Level.FINE, "Handeling gamemode for player: " + player.getName());
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||
new Runnable() {
|
||||
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, "Handling gamemode for player: " + player.getName() + ", " + world.getGameMode().toString());
|
||||
MultiverseCore.staticLog(Level.FINE, "PWorld: " + player.getWorld());
|
||||
MultiverseCore.staticLog(Level.FINE, "AWorld: " + world);
|
||||
MultiverseCore.staticLog(Level.FINE, "Handling gamemode for player: "
|
||||
+ player.getName() + ", Changing to " + world.getGameMode().toString());
|
||||
MultiverseCore.staticLog(Level.FINEST, "From World: " + player.getWorld());
|
||||
MultiverseCore.staticLog(Level.FINEST, "To World: " + world);
|
||||
player.setGameMode(world.getGameMode());
|
||||
} else {
|
||||
MultiverseCore.staticLog(Level.FINE,
|
||||
String.format("The gamemode was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
|
||||
player.getName(), player.getWorld().getName(), world.getName()));
|
||||
MultiverseCore.staticLog(Level.FINE, "The gamemode was NOT changed for player '"
|
||||
+ player.getName() + "' because he is now in world '"
|
||||
+ player.getWorld().getName() + "' instead of world '"
|
||||
+ world.getName() +"'");
|
||||
}
|
||||
}
|
||||
}, 1L);
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Multiverse's Plugin {@link Listener}.
|
||||
@@ -40,10 +39,12 @@ public class MVPluginListener implements Listener {
|
||||
this.plugin.setBank(this.plugin.getBanker().loadEconPlugin());
|
||||
}
|
||||
|
||||
/*
|
||||
if (event.getPlugin().getDescription().getName().equals("Spout")) {
|
||||
this.plugin.setSpout();
|
||||
this.plugin.log(Level.INFO, "Spout integration enabled.");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MVPortalListener implements Listener {
|
||||
}
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
|
||||
// We have to do it like this due to a bug in 1.1-R3
|
||||
if (this.cancelPortalEvent(world, event.getPortalType())) {
|
||||
if (cancelPortalEvent(world, event.getPortalType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class MVPortalListener implements Listener {
|
||||
for (Block b : event.getBlocks()) {
|
||||
if (b.getType() == Material.PORTAL) {
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(b.getWorld());
|
||||
if (this.cancelPortalEvent(world, PortalType.NETHER)) {
|
||||
if (cancelPortalEvent(world, PortalType.NETHER)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -67,12 +67,12 @@ public class MVPortalListener implements Listener {
|
||||
}
|
||||
// If We're here, then the Portal was an Ender type:
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
|
||||
if (this.cancelPortalEvent(world, PortalType.ENDER)) {
|
||||
if (cancelPortalEvent(world, PortalType.ENDER)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean cancelPortalEvent(MultiverseWorld world, PortalType type) {
|
||||
private static boolean cancelPortalEvent(MultiverseWorld world, PortalType type) {
|
||||
if (world.getAllowedPortals() == AllowedPortalType.NONE) {
|
||||
return true;
|
||||
} else if (world.getAllowedPortals() != AllowedPortalType.ALL) {
|
||||
|
||||
@@ -7,10 +7,14 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCoreConfiguration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Handler;
|
||||
@@ -21,10 +25,10 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
* The Multiverse debug-logger.
|
||||
*/
|
||||
public class DebugLog {
|
||||
|
||||
public class DebugLog extends Logger {
|
||||
private FileHandler fh;
|
||||
private Logger log;
|
||||
private Logger standardLog = null;
|
||||
private String prefix = "[MVCore-Debug] ";
|
||||
|
||||
/**
|
||||
* Creates a new debug logger.
|
||||
@@ -33,16 +37,16 @@ public class DebugLog {
|
||||
* @param file The file to log to.
|
||||
*/
|
||||
public DebugLog(String logger, String file) {
|
||||
this.log = Logger.getLogger(logger);
|
||||
|
||||
super(logger, null);
|
||||
try {
|
||||
this.fh = new FileHandler(file, true);
|
||||
this.log.setUseParentHandlers(false);
|
||||
for (Handler handler : this.log.getHandlers()) {
|
||||
this.log.removeHandler(handler);
|
||||
this.setUseParentHandlers(false);
|
||||
List<Handler> toRemove = Arrays.asList(this.getHandlers());
|
||||
for (Handler handler : toRemove) {
|
||||
this.removeHandler(handler);
|
||||
}
|
||||
this.log.addHandler(this.fh);
|
||||
this.log.setLevel(Level.ALL);
|
||||
this.addHandler(this.fh);
|
||||
this.setLevel(Level.ALL);
|
||||
this.fh.setFormatter(new LogFormatter());
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
@@ -51,14 +55,39 @@ public class DebugLog {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the log-tag.
|
||||
* @param tag The new tag.
|
||||
*/
|
||||
public void setTag(String tag) {
|
||||
this.prefix = tag + " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the logger to use to send debug messages to as the debug logger itself only sends messages to a file.
|
||||
*
|
||||
* @param logger Logger to send debug messages to.
|
||||
*/
|
||||
public void setStandardLogger(Logger logger) {
|
||||
this.standardLog = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at a certain level.
|
||||
*
|
||||
* @param level The log-{@link Level}.
|
||||
* @param msg the message.
|
||||
*/
|
||||
@Override
|
||||
public void log(Level level, String msg) {
|
||||
this.log.log(level, msg);
|
||||
if (MultiverseCoreConfiguration.isSet() && MultiverseCoreConfiguration.getInstance().getGlobalDebug() > 0) {
|
||||
// only redirect to standardLog if it's lower than INFO so we don't log that twice!
|
||||
if ((level.intValue() < Level.INFO.intValue()) && (standardLog != null)) {
|
||||
standardLog.log(level, prefix + msg);
|
||||
}
|
||||
|
||||
super.log(level, prefix + msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,9 +20,11 @@ public class FancyMessage implements FancyText {
|
||||
|
||||
/**
|
||||
* Allows easy creation of an alternating colored list.
|
||||
* TODO: Documentation! Why does CheckStyle just ignore this?
|
||||
*
|
||||
* @param title
|
||||
* @param message
|
||||
* @param scheme
|
||||
*/
|
||||
public FancyMessage(String title, String message, FancyColorScheme scheme) {
|
||||
this.title = title;
|
||||
|
||||
@@ -25,19 +25,16 @@ public class FileUtils {
|
||||
*/
|
||||
public static boolean deleteFolder(File file) {
|
||||
if (file.exists()) {
|
||||
boolean ret = true;
|
||||
// If the file exists, and it has more than one file in it.
|
||||
if (file.isDirectory()) {
|
||||
for (File f : file.listFiles()) {
|
||||
if (!FileUtils.deleteFolder(f)) {
|
||||
return false;
|
||||
}
|
||||
ret = ret && deleteFolder(f);
|
||||
}
|
||||
}
|
||||
file.delete();
|
||||
return !file.exists();
|
||||
return ret && file.delete();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -249,7 +249,6 @@ public class LocationManipulation {
|
||||
}
|
||||
float speed = getSpeed(v);
|
||||
float halfSpeed = (float) (speed / 2.0);
|
||||
// TODO: Mathmatacize this:
|
||||
if (direction.equalsIgnoreCase("n")) {
|
||||
return new Vector(0, 0, -1 * speed);
|
||||
} else if (direction.equalsIgnoreCase("ne")) {
|
||||
|
||||
@@ -51,17 +51,17 @@ public class MVMessaging implements MultiverseMessaging {
|
||||
public boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown) {
|
||||
if (!(sender instanceof Player) || ignoreCooldown) {
|
||||
|
||||
this.sendMessages(sender, messages);
|
||||
sendMessages(sender, messages);
|
||||
return true;
|
||||
}
|
||||
if (!this.sentList.containsKey(sender.getName())) {
|
||||
this.sendMessages(sender, messages);
|
||||
sendMessages(sender, messages);
|
||||
this.sentList.put(sender.getName(), System.currentTimeMillis());
|
||||
return true;
|
||||
} else {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time >= this.sentList.get(sender.getName()) + this.cooldown) {
|
||||
this.sendMessages(sender, messages);
|
||||
sendMessages(sender, messages);
|
||||
this.sentList.put(sender.getName(), System.currentTimeMillis());
|
||||
return true;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class MVMessaging implements MultiverseMessaging {
|
||||
return this.sendMessages(sender, messages.toArray(new String[0]), ignoreCooldown);
|
||||
}
|
||||
|
||||
private void sendMessages(CommandSender sender, String[] messages) {
|
||||
private static void sendMessages(CommandSender sender, String[] messages) {
|
||||
for (String s : messages) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.pneumaticraft.commandhandler.PermissionsInterface;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -139,6 +140,87 @@ public class MVPermissions implements PermissionsInterface {
|
||||
return this.hasPermission(p, d.getRequiredPermission(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells a {@link CommandSender} why another {@link CommandSender} can or can not access a certain {@link MVDestination}.
|
||||
* @param asker The {@link CommandSender} that's asking.
|
||||
* @param playerInQuestion The {@link CommandSender} whose permissions we want to know.
|
||||
* @param d The {@link MVDestination}.
|
||||
*/
|
||||
public void tellMeWhyICantDoThis(CommandSender asker, CommandSender playerInQuestion, MVDestination d) {
|
||||
boolean cango = true;
|
||||
if (!(playerInQuestion instanceof Player)) {
|
||||
asker.sendMessage(String.format("The console can do %severything%s.", ChatColor.RED, ChatColor.WHITE));
|
||||
return;
|
||||
}
|
||||
Player p = (Player) playerInQuestion;
|
||||
if (d == null) {
|
||||
asker.sendMessage(String.format("The provided Destination is %sNULL%s, and therefore %sINVALID%s.",
|
||||
ChatColor.RED, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
// We know it'll be a player here due to the first line of this method.
|
||||
if (d.getLocation(p) == null) {
|
||||
asker.sendMessage(String.format(
|
||||
"The player will spawn at an %sindeterminate location%s. Talk to the MV Devs if you see this",
|
||||
ChatColor.RED, ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
String worldName = d.getLocation(p).getWorld().getName();
|
||||
if (!this.worldMgr.isMVWorld(worldName)) {
|
||||
asker.sendMessage(String.format("The destination resides in a world(%s%s%s) that is not managed by Multiverse.",
|
||||
ChatColor.AQUA, worldName, ChatColor.WHITE));
|
||||
asker.sendMessage(String.format("Type %s/mv import ?%s to see the import command's help page.",
|
||||
ChatColor.DARK_AQUA, ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
if (!this.hasPermission(p, "multiverse.access." + worldName, false)) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) does not have the required world entry permission (%s%s%s) to go to the destination (%s%s%s).",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.access." + worldName, ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
if (!this.hasPermission(p, d.getRequiredPermission(), false)) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) does not have the required entry permission (%s%s%s) to go to the destination (%s%s%s).",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, d.getRequiredPermission(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
if (cango) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) CAN go to the destination (%s%s%s).",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
} else {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) cannot access the destination %s%s%s. Therefore they can't use mvtp at all for this.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
return;
|
||||
}
|
||||
if (!this.hasPermission(p, "multiverse.teleport.self." + d.getIdentifier(), false)) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) does not have the required teleport permission (%s%s%s) to use %s/mvtp %s%s.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.teleport.self." + d.getIdentifier(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
} else {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) has the required teleport permission (%s%s%s) to use %s/mvtp %s%s.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.teleport.self." + d.getIdentifier(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
}
|
||||
if (!this.hasPermission(p, "multiverse.teleport.other." + d.getIdentifier(), false)) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) does not have the required teleport permission (%s%s%s) to send others to %s%s%s via mvtp.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.teleport.other." + d.getIdentifier(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
} else {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) has required teleport permission (%s%s%s) to send others to %s%s%s via mvtp.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.teleport.other." + d.getIdentifier(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a player has a permission.
|
||||
*
|
||||
@@ -147,6 +229,7 @@ public class MVPermissions implements PermissionsInterface {
|
||||
* @param isOpRequired @Deprecated. This is not used for anything anymore.
|
||||
* @return True if they have that permission or any parent.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender, String node, boolean isOpRequired) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
@@ -160,17 +243,8 @@ public class MVPermissions implements PermissionsInterface {
|
||||
if (node.equals("")) {
|
||||
return true;
|
||||
}
|
||||
boolean hasPermission = checkActualPermission(sender, node);
|
||||
|
||||
// I consider this a workaround. At the moment, when we add a node AND recalc the permissions, until the perms
|
||||
// plugin reloads, when MV asks the API if a player has a perm, it reports that they do NOT.
|
||||
// For the moment, we're going to check all of this node's parents to see if the user has those. It stops
|
||||
// when if finds a true or there are no more parents. --FF
|
||||
// if (!hasPermission) {
|
||||
// hasPermission = this.hasAnyParentPermission(sender, node);
|
||||
// }
|
||||
|
||||
return hasPermission;
|
||||
return checkActualPermission(sender, node);
|
||||
}
|
||||
|
||||
// TODO: Better player checks, most likely not needed, but safer.
|
||||
@@ -178,10 +252,15 @@ public class MVPermissions implements PermissionsInterface {
|
||||
Player player = (Player) sender;
|
||||
|
||||
boolean hasPermission = sender.hasPermission(node);
|
||||
if (!sender.isPermissionSet(node)) {
|
||||
this.plugin.log(Level.FINER, String.format("The node [%s%s%s] was %sNOT%s set for [%s%s%s].",
|
||||
ChatColor.RED, node, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE, ChatColor.AQUA,
|
||||
player.getDisplayName(), ChatColor.WHITE));
|
||||
}
|
||||
if (hasPermission) {
|
||||
this.plugin.log(Level.FINEST, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... YES");
|
||||
this.plugin.log(Level.FINER, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... YES");
|
||||
} else {
|
||||
this.plugin.log(Level.FINEST, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... NO");
|
||||
this.plugin.log(Level.FINER, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... NO");
|
||||
}
|
||||
return hasPermission;
|
||||
}
|
||||
@@ -195,6 +274,7 @@ public class MVPermissions implements PermissionsInterface {
|
||||
* @param node The permission node to check (possibly already a parent).
|
||||
* @return True if they have any parent perm, false if none.
|
||||
*/
|
||||
// TODO remove this...?
|
||||
private boolean hasAnyParentPermission(CommandSender sender, String node) {
|
||||
String parentPerm = this.pullOneLevelOff(node);
|
||||
// Base case
|
||||
@@ -215,7 +295,7 @@ public class MVPermissions implements PermissionsInterface {
|
||||
* @param node The root node to check.
|
||||
* @return The parent of the node
|
||||
*/
|
||||
private String pullOneLevelOff(String node) {
|
||||
private static String pullOneLevelOff(String node) {
|
||||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -320,7 +400,7 @@ public class MVPermissions implements PermissionsInterface {
|
||||
/**
|
||||
* If the given permission was 'multiverse.core.tp.self', this would return 'multiverse.core.tp.*'.
|
||||
*/
|
||||
private String getParentPerm(String[] seperated) {
|
||||
private static String getParentPerm(String[] seperated) {
|
||||
if (seperated.length == 1) {
|
||||
return null;
|
||||
}
|
||||
@@ -330,5 +410,4 @@ public class MVPermissions implements PermissionsInterface {
|
||||
}
|
||||
return returnString + "*";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
@@ -16,6 +15,8 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Utility-class for permissions.
|
||||
*/
|
||||
@@ -78,7 +79,7 @@ public class PermissionTools {
|
||||
* @param separatedPermissionString The array of a dot separated perm string.
|
||||
* @return The dot separated parent permission string.
|
||||
*/
|
||||
private String getParentPerm(String[] separatedPermissionString) {
|
||||
private static String getParentPerm(String[] separatedPermissionString) {
|
||||
if (separatedPermissionString.length == 1) {
|
||||
return null;
|
||||
}
|
||||
@@ -134,6 +135,10 @@ public class PermissionTools {
|
||||
|
||||
// Only check payments if it's a different world:
|
||||
if (!toWorld.equals(fromWorld)) {
|
||||
// Don't bother checking economy stuff if it doesn't even cost to enter.
|
||||
if (toWorld.getPrice() == 0D) {
|
||||
return true;
|
||||
}
|
||||
// If the player does not have to pay, return now.
|
||||
if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) {
|
||||
return true;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PurgeWorlds {
|
||||
/**
|
||||
* Convenience method for {@link #purgeWorld(CommandSender, MultiverseWorld, List, boolean, boolean)} that takes the settings from the world-config.
|
||||
*
|
||||
* @param sender The {@link CommandSender} that initiated the action (TODO: Do we really need this?)
|
||||
* @param sender The {@link CommandSender} that initiated the action
|
||||
* @param world The {@link MultiverseWorld}.
|
||||
*/
|
||||
public void purgeWorld(CommandSender sender, MultiverseWorld world) {
|
||||
@@ -70,7 +70,7 @@ public class PurgeWorlds {
|
||||
|
||||
/**
|
||||
* Clear all animals/monsters that do not belong to a world according to the config.
|
||||
* @param sender The {@link CommandSender} that initiated the action. (TODO: Do we really need this?)
|
||||
* @param sender The {@link CommandSender} that initiated the action.
|
||||
* @param mvworld The {@link MultiverseWorld}.
|
||||
* @param thingsToKill A {@link List} of animals/monsters to be killed.
|
||||
* @param negateAnimals Whether the monsters in the list should be negated.
|
||||
@@ -127,14 +127,13 @@ public class PurgeWorlds {
|
||||
*/
|
||||
private boolean killMonster(MultiverseWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = "";
|
||||
//TODO: Fixme once either Rigby puts his awesome thing in OR Enderdragon gets a toString, OR both.
|
||||
if (e instanceof EnderDragon) {
|
||||
entityName = "ENDERDRAGON";
|
||||
} else {
|
||||
entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
}
|
||||
if (e instanceof Slime || e instanceof Monster || e instanceof Ghast || e instanceof EnderDragon) {
|
||||
this.plugin.log(Level.FINER, "Looking at a monster: " + e);
|
||||
this.plugin.log(Level.FINEST, "Looking at a monster: " + e);
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("MONSTERS")) {
|
||||
if (!negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing a monster: " + e);
|
||||
|
||||
@@ -63,7 +63,6 @@ public class SafeTTeleporter {
|
||||
*/
|
||||
public Location getSafeLocation(Location l, int tolerance, int radius) {
|
||||
// Check around the player first in a configurable radius:
|
||||
// TODO: Make this configurable
|
||||
Location safe = checkAboveAndBelowLocation(l, tolerance, radius);
|
||||
if (safe != null) {
|
||||
safe.setX(safe.getBlockX() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
|
||||
@@ -65,24 +65,24 @@ public class SimpleBlockSafety implements BlockSafety {
|
||||
upOne.setY(upOne.getY() + 1);
|
||||
downOne.setY(downOne.getY() - 1);
|
||||
|
||||
if (this.isSolidBlock(world.getBlockAt(actual).getType())
|
||||
|| this.isSolidBlock(upOne.getBlock().getType())) {
|
||||
if (isSolidBlock(world.getBlockAt(actual).getType())
|
||||
|| isSolidBlock(upOne.getBlock().getType())) {
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here (Actual)? ("
|
||||
+ actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
+ actual.getBlock().getType() + ")[" + isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here (upOne)? ("
|
||||
+ upOne.getBlock().getType() + ")[" + this.isSolidBlock(upOne.getBlock().getType()) + "]");
|
||||
+ upOne.getBlock().getType() + ")[" + isSolidBlock(upOne.getBlock().getType()) + "]");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here (downOne)? ("
|
||||
+ downOne.getBlock().getType() + ")[" + this.isSolidBlock(downOne.getBlock().getType()) + "]");
|
||||
+ downOne.getBlock().getType() + ")[" + isSolidBlock(downOne.getBlock().getType()) + "]");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (downOne.getBlock().getType() == Material.FIRE) {
|
||||
MultiverseCore.staticLog(Level.FINER, "There's fire below! ("
|
||||
+ actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
+ actual.getBlock().getType() + ")[" + isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class SimpleBlockSafety implements BlockSafety {
|
||||
/*
|
||||
* If someone has a better way of this... Please either tell us, or submit a pull request!
|
||||
*/
|
||||
private boolean isSolidBlock(Material type) {
|
||||
private static boolean isSolidBlock(Material type) {
|
||||
switch (type) {
|
||||
case AIR:
|
||||
return false;
|
||||
|
||||
@@ -14,8 +14,8 @@ import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Slime;
|
||||
@@ -71,23 +71,59 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
if (mvworld == null) {
|
||||
return;
|
||||
}
|
||||
World world = this.plugin.getServer().getWorld(mvworld.getName());
|
||||
World world = mvworld.getCBWorld();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
int entitiesKilled = 0;
|
||||
boolean specifiedAll = thingsToKill.contains("ALL");
|
||||
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
|
||||
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
|
||||
for (Entity e : world.getEntities()) {
|
||||
this.plugin.log(Level.FINEST, "Entity list (aval for purge) from WORLD < " + mvworld.getName() + " >: " + e.toString());
|
||||
|
||||
// Check against Monsters
|
||||
if (killMonster(mvworld, e, thingsToKill, negateMonsters)) {
|
||||
boolean negate = false;
|
||||
boolean specified = false;
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
// it's an animal
|
||||
if (specifiedAnimals && !negateAnimals) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all animals: " + e);
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
if (specifiedAnimals)
|
||||
specified = true;
|
||||
negate = negateAnimals;
|
||||
} else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
|
||||
// it's a monster
|
||||
if (specifiedMonsters && !negateMonsters) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
if (specifiedMonsters)
|
||||
specified = true;
|
||||
negate = negateMonsters;
|
||||
}
|
||||
for (String s : thingsToKill) {
|
||||
EntityType type = EntityType.fromName(s);
|
||||
if (type != null && type.equals(e.getType())) {
|
||||
specified = true;
|
||||
if (!negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because it WAS specified and we are NOT negating: " + e);
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!specified && negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because it was NOT specified and we ARE negating: " + e);
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
// Check against Animals
|
||||
if (this.killCreature(mvworld, e, thingsToKill, negateAnimals)) {
|
||||
entitiesKilled++;
|
||||
}
|
||||
}
|
||||
if (sender != null) {
|
||||
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "'");
|
||||
@@ -101,53 +137,4 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
public void purgeWorld(MultiverseWorld mvworld, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters) {
|
||||
purgeWorld(mvworld, thingsToKill, negateAnimals, negateMonsters, null);
|
||||
}
|
||||
|
||||
private boolean killCreature(MultiverseWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("ANIMALS")) {
|
||||
if (!negate) {
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (negate) {
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Will kill the monster if it's in the list UNLESS the NEGATE boolean is set, then it will kill it if it's NOT.
|
||||
*/
|
||||
private boolean killMonster(MultiverseWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = "";
|
||||
//TODO: Fixme once either Rigby puts his awesome thing in OR Enderdragon gets a toString, OR both.
|
||||
if (e instanceof EnderDragon) {
|
||||
entityName = "ENDERDRAGON";
|
||||
} else {
|
||||
entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
}
|
||||
if (e instanceof Slime || e instanceof Monster || e instanceof Ghast || e instanceof EnderDragon) {
|
||||
this.plugin.log(Level.FINER, "Looking at a monster: " + e);
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("MONSTERS")) {
|
||||
if (!negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing a monster: " + e);
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing a monster: " + e);
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,14 +4,14 @@
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
|
||||
/**
|
||||
* A helper-class holding the {@link SpoutManager}.
|
||||
*/
|
||||
* /
|
||||
public class SpoutInterface {
|
||||
private SpoutManager spoutManager;
|
||||
|
||||
@@ -22,8 +22,9 @@ public class SpoutInterface {
|
||||
/**
|
||||
* Gets the {@link SpoutManager}.
|
||||
* @return The {@link SpoutManager}.
|
||||
*/
|
||||
* /
|
||||
public SpoutManager getManager() {
|
||||
return this.spoutManager;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@@ -54,6 +55,7 @@ public class UpdateChecker {
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
BufferedReader rd = null;
|
||||
try {
|
||||
URL url = new URL("http://bukkit.onarandombox.com/multiverse/version.php?n=" + URLEncoder.encode(this.name, "UTF-8") + "&v=" + this.cversion);
|
||||
URLConnection conn = url.openConnection();
|
||||
@@ -65,7 +67,7 @@ public class UpdateChecker {
|
||||
return;
|
||||
}
|
||||
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
String version = null;
|
||||
|
||||
@@ -76,7 +78,6 @@ public class UpdateChecker {
|
||||
}
|
||||
|
||||
if (version == null) {
|
||||
rd.close();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,6 +93,12 @@ public class UpdateChecker {
|
||||
rd.close();
|
||||
} catch (Exception e) {
|
||||
// No need to alert the user of any error here... it's not important.
|
||||
} finally {
|
||||
if (rd != null) {
|
||||
try {
|
||||
rd.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,13 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
||||
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -36,6 +37,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
@@ -44,16 +46,16 @@ import java.util.logging.Level;
|
||||
public class WorldManager implements MVWorldManager {
|
||||
private MultiverseCore plugin;
|
||||
private WorldPurger worldPurger;
|
||||
private Map<String, MVWorld> worldsFromTheConfig;
|
||||
private Map<String, MultiverseWorld> worlds;
|
||||
private List<String> unloadedWorlds;
|
||||
private FileConfiguration configWorlds = null;
|
||||
private Map<String, String> defaultGens;
|
||||
private String firstSpawn;
|
||||
|
||||
public WorldManager(MultiverseCore core) {
|
||||
this.plugin = core;
|
||||
this.worldsFromTheConfig = new HashMap<String, MVWorld>();
|
||||
this.worlds = new HashMap<String, MultiverseWorld>();
|
||||
this.unloadedWorlds = new ArrayList<String>();
|
||||
this.worldPurger = new SimpleWorldPurger(plugin);
|
||||
}
|
||||
|
||||
@@ -69,7 +71,7 @@ public class WorldManager implements MVWorldManager {
|
||||
return s.equalsIgnoreCase("bukkit.yml");
|
||||
}
|
||||
});
|
||||
if (files.length == 1) {
|
||||
if (files != null && files.length == 1) {
|
||||
FileConfiguration bukkitConfig = YamlConfiguration.loadConfiguration(files[0]);
|
||||
if (bukkitConfig.isConfigurationSection("worlds")) {
|
||||
Set<String> keys = bukkitConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
@@ -77,6 +79,8 @@ public class WorldManager implements MVWorldManager {
|
||||
defaultGens.put(key, bukkitConfig.getString("worlds." + key + ".generator", ""));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.plugin.log(Level.WARNING, "Could not read 'bukkit.yml'. Any Default worldgenerators will not be loaded!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +122,10 @@ public class WorldManager implements MVWorldManager {
|
||||
c.generateStructures(generateStructures);
|
||||
}
|
||||
|
||||
World world;
|
||||
// Important: doLoad() needs the MVWorld-object in worldsFromTheConfig
|
||||
if (!worldsFromTheConfig.containsKey(name))
|
||||
worldsFromTheConfig.put(name, new MVWorld(useSpawnAdjust));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Loading World & Settings - '").append(name).append("'");
|
||||
builder.append(" - Env: ").append(env);
|
||||
@@ -131,40 +138,16 @@ public class WorldManager implements MVWorldManager {
|
||||
}
|
||||
this.plugin.log(Level.INFO, builder.toString());
|
||||
|
||||
try {
|
||||
world = c.createWorld();
|
||||
} catch (Exception e) {
|
||||
this.plugin.log(Level.SEVERE, "The world '" + name + "' could NOT be loaded because it contains errors!");
|
||||
this.plugin.log(Level.SEVERE, "Try using Chukster to repair your world! '" + name + "'");
|
||||
this.plugin.log(Level.SEVERE, "http://forums.bukkit.org/threads/admin-chunkster.8186/");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
if (!doLoad(c)) {
|
||||
this.plugin.log(Level.SEVERE, "Failed to Create/Load the world '" + name + "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
MultiverseWorld mvworld = new MVWorld(world, this.configWorlds, this.plugin,
|
||||
this.plugin.getServer().getWorld(name).getSeed(), generator, useSpawnAdjust);
|
||||
this.worldPurger.purgeWorld(mvworld);
|
||||
this.worlds.put(name, mvworld);
|
||||
if (this.unloadedWorlds.contains(name)) {
|
||||
this.unloadedWorlds.remove(name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// set generator (special case because we can't read it from org.bukkit.World)
|
||||
this.worlds.get(name).setGenerator(generator);
|
||||
|
||||
/**
|
||||
* Verifies that a given Plugin generator string exists.
|
||||
*
|
||||
* @param generator The name of the generator plugin. This should be something like CleanRoomGenerator.
|
||||
* @return True if the plugin exists and is enabled, false if not.
|
||||
*/
|
||||
// TODO maybe remove this since it's unused?
|
||||
private boolean pluginExists(String generator) {
|
||||
Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
|
||||
return myPlugin != null && myPlugin.isEnabled();
|
||||
this.saveWorldsConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,15 +175,11 @@ public class WorldManager implements MVWorldManager {
|
||||
if (!unloadWorld(name)) {
|
||||
return false;
|
||||
}
|
||||
if (this.configWorlds.get("worlds." + name) != null) {
|
||||
if (this.worldsFromTheConfig.containsKey(name)) {
|
||||
this.worldsFromTheConfig.remove(name);
|
||||
this.plugin.log(Level.INFO, "World '" + name + "' was removed from config.yml");
|
||||
this.configWorlds.set("worlds." + name, null);
|
||||
|
||||
this.saveWorldsConfig();
|
||||
// Remove it from the list of unloaded worlds.
|
||||
if (this.unloadedWorlds.contains(name)) {
|
||||
this.unloadedWorlds.remove(name);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
this.plugin.log(Level.INFO, "World '" + name + "' was already removed from config.yml");
|
||||
@@ -248,15 +227,17 @@ public class WorldManager implements MVWorldManager {
|
||||
if (this.unloadWorldFromBukkit(name, true)) {
|
||||
this.worlds.remove(name);
|
||||
this.plugin.log(Level.INFO, "World '" + name + "' was unloaded from memory.");
|
||||
this.unloadedWorlds.add(name);
|
||||
|
||||
this.worldsFromTheConfig.get(name).tearDown();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
this.plugin.log(Level.WARNING, "World '" + name + "' could not be unloaded. Is it a default world?");
|
||||
}
|
||||
} else if (this.plugin.getServer().getWorld(name) != null) {
|
||||
this.plugin.log(Level.WARNING, "Hmm Multiverse does not know about this world but it's loaded in memory.");
|
||||
this.plugin.log(Level.WARNING, "To unload it using multiverse, use:");
|
||||
this.plugin.log(Level.WARNING, "/mv import " + name + " " + this.plugin.getServer().getWorld(name).getEnvironment().toString());
|
||||
this.plugin.log(Level.WARNING, "To let Multiverse know about it, use:");
|
||||
this.plugin.log(Level.WARNING, String.format("/mv import %s %s", name, this.plugin.getServer().getWorld(name).getEnvironment().toString()));
|
||||
} else {
|
||||
this.plugin.log(Level.INFO, "Multiverse does not know about " + name + " and it's not loaded by Bukkit.");
|
||||
}
|
||||
@@ -270,36 +251,60 @@ public class WorldManager implements MVWorldManager {
|
||||
public boolean loadWorld(String name) {
|
||||
// Check if the World is already loaded
|
||||
if (this.worlds.containsKey(name)) {
|
||||
// Ensure it's not unloaded, since it IS loaded.
|
||||
if (this.unloadedWorlds.contains(name)) {
|
||||
this.unloadedWorlds.remove(name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Grab all the Worlds from the Config.
|
||||
Set<String> worldKeys = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
|
||||
|
||||
// Check that the list is not null and that the config contains the world
|
||||
if ((worldKeys != null) && (worldKeys.contains(name))) {
|
||||
// Grab the initial values from the config file.
|
||||
String environment = this.configWorlds.getString("worlds." + name + ".environment", "NORMAL"); // Grab the Environment as a String.
|
||||
String type = this.configWorlds.getString("worlds." + name + ".type", "NORMAL");
|
||||
String seedString = this.configWorlds.getString("worlds." + name + ".seed", "");
|
||||
String generatorString = this.configWorlds.getString("worlds." + name + ".generator");
|
||||
boolean generateStructures = this.configWorlds.getBoolean("worlds." + name + ".generatestructures", true);
|
||||
|
||||
this.addWorld(name, EnvironmentCommand.getEnvFromString(environment), seedString,
|
||||
EnvironmentCommand.getWorldTypeFromString(type), generateStructures, generatorString);
|
||||
if (this.unloadedWorlds.contains(name)) {
|
||||
this.unloadedWorlds.remove(name);
|
||||
}
|
||||
return true;
|
||||
// Check that the world is in the config
|
||||
if (worldsFromTheConfig.containsKey(name)) {
|
||||
return doLoad(name);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void brokenWorld(String name) {
|
||||
this.plugin.log(Level.SEVERE, "The world '" + name + "' could NOT be loaded because it contains errors!");
|
||||
this.plugin.log(Level.SEVERE, "Try using Chukster to repair your world! '" + name + "'");
|
||||
this.plugin.log(Level.SEVERE, "http://forums.bukkit.org/threads/admin-chunkster.8186/");
|
||||
}
|
||||
|
||||
private boolean doLoad(String name) {
|
||||
if (!worldsFromTheConfig.containsKey(name))
|
||||
throw new IllegalArgumentException("That world doesn't exist!");
|
||||
|
||||
MVWorld world = worldsFromTheConfig.get(name);
|
||||
WorldCreator creator = WorldCreator.name(name);
|
||||
|
||||
creator.environment(world.getEnvironment()).seed(world.getSeed());
|
||||
if ((world.getGenerator() != null) && (!world.getGenerator().equals("null")))
|
||||
creator.generator(world.getGenerator());
|
||||
|
||||
return doLoad(creator);
|
||||
}
|
||||
|
||||
private boolean doLoad(WorldCreator creator) {
|
||||
String worldName = creator.name();
|
||||
if (!worldsFromTheConfig.containsKey(worldName))
|
||||
throw new IllegalArgumentException("That world doesn't exist!");
|
||||
if (worlds.containsKey(worldName))
|
||||
throw new IllegalArgumentException("That world is already loaded!");
|
||||
MVWorld mvworld = worldsFromTheConfig.get(worldName);
|
||||
World cbworld = Bukkit.getWorld(worldName);
|
||||
if (cbworld == null) {
|
||||
try {
|
||||
cbworld = creator.createWorld();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
brokenWorld(worldName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
mvworld.init(cbworld, plugin);
|
||||
this.worldPurger.purgeWorld(mvworld);
|
||||
this.worlds.put(worldName, mvworld);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -471,30 +476,22 @@ public class WorldManager implements MVWorldManager {
|
||||
public void loadDefaultWorlds() {
|
||||
this.ensureConfigIsPrepared();
|
||||
List<World> myWorlds = this.plugin.getServer().getWorlds();
|
||||
Set<String> worldStrings = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
|
||||
for (World w : myWorlds) {
|
||||
String name = w.getName();
|
||||
if (!worldStrings.contains(name)) {
|
||||
if (!worldsFromTheConfig.containsKey(name)) {
|
||||
String generator = null;
|
||||
if (this.defaultGens.containsKey(name)) {
|
||||
this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(),
|
||||
w.canGenerateStructures(), this.defaultGens.get(name));
|
||||
} else {
|
||||
this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(),
|
||||
w.canGenerateStructures(), null);
|
||||
generator = this.defaultGens.get(name);
|
||||
}
|
||||
|
||||
this.addWorld(name, w.getEnvironment(), String.valueOf(w.getSeed()), w.getWorldType(), w.canGenerateStructures(), generator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureConfigIsPrepared() {
|
||||
this.configWorlds.options().pathSeparator(SEPARATOR);
|
||||
if (this.configWorlds.getConfigurationSection("worlds") == null) {
|
||||
this.configWorlds.createSection("worlds");
|
||||
try {
|
||||
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
||||
} catch (IOException e) {
|
||||
this.plugin.log(Level.SEVERE, "Failed to save worlds.yml. Please check your file permissions.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,13 +504,10 @@ public class WorldManager implements MVWorldManager {
|
||||
int count = 0;
|
||||
this.ensureConfigIsPrepared();
|
||||
this.ensureSecondNamespaceIsPrepared();
|
||||
// Grab all the Worlds from the Config.
|
||||
Set<String> worldKeys = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
|
||||
|
||||
// Force the worlds to be loaded, ie don't just load new worlds.
|
||||
if (forceLoad) {
|
||||
// Remove all world permissions.
|
||||
|
||||
Permission allAccess = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
|
||||
Permission allExempt = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*");
|
||||
for (MultiverseWorld w : this.worlds.values()) {
|
||||
@@ -535,45 +529,19 @@ public class WorldManager implements MVWorldManager {
|
||||
this.worlds.clear();
|
||||
}
|
||||
|
||||
// Check that the list is not null.
|
||||
if (worldKeys != null) {
|
||||
for (String worldKey : worldKeys) {
|
||||
// Check if the World is already loaded within the Plugin.
|
||||
if (this.worlds.containsKey(worldKey)) {
|
||||
continue;
|
||||
}
|
||||
for (Map.Entry<String, MVWorld> entry : worldsFromTheConfig.entrySet()) {
|
||||
if (worlds.containsKey(entry.getKey()))
|
||||
continue;
|
||||
if (!entry.getValue().getAutoLoad())
|
||||
continue;
|
||||
|
||||
// If autoload was set to false, don't load this one.
|
||||
if (!this.configWorlds.getBoolean("worlds." + worldKey + ".autoload", true)) {
|
||||
if (!this.unloadedWorlds.contains(worldKey)) {
|
||||
this.unloadedWorlds.add(worldKey);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Grab the initial values from the config file.
|
||||
String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL");
|
||||
String type = this.configWorlds.getString("worlds." + worldKey + ".type", "NORMAL");
|
||||
String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", null);
|
||||
boolean generateStructures = this.configWorlds.getBoolean("worlds." + worldKey + ".generatestructures", true);
|
||||
if (seedString == null) {
|
||||
seedString = this.configWorlds.getLong("worlds." + worldKey + ".seed") + "";
|
||||
}
|
||||
|
||||
String generatorString = this.configWorlds.getString("worlds." + worldKey + ".generator");
|
||||
if (environment.equalsIgnoreCase("skylands")) {
|
||||
this.plugin.log(Level.WARNING, "Found SKYLANDS world. Not importing automatically, as it won't work atm :(");
|
||||
continue;
|
||||
}
|
||||
addWorld(worldKey, EnvironmentCommand.getEnvFromString(environment), seedString,
|
||||
EnvironmentCommand.getWorldTypeFromString(type), generateStructures, generatorString);
|
||||
|
||||
// Increment the world count
|
||||
if (doLoad(entry.getKey()))
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
// Simple Output to the Console to show how many Worlds were loaded.
|
||||
this.plugin.log(Level.INFO, count + " - World(s) loaded.");
|
||||
this.saveWorldsConfig();
|
||||
}
|
||||
|
||||
private void ensureSecondNamespaceIsPrepared() {
|
||||
@@ -602,15 +570,54 @@ public class WorldManager implements MVWorldManager {
|
||||
return worldPurger;
|
||||
}
|
||||
|
||||
private static final char SEPARATOR = '\uF8FF';
|
||||
|
||||
/**
|
||||
* Load the config from a file.
|
||||
*
|
||||
* @param file The file to load.
|
||||
* @return A loaded configuration.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public FileConfiguration loadWorldConfig(File file) {
|
||||
this.configWorlds = YamlConfiguration.loadConfiguration(file);
|
||||
this.ensureConfigIsPrepared();
|
||||
try {
|
||||
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
// load world-objects
|
||||
Stack<String> worldKeys = new Stack<String>();
|
||||
worldKeys.addAll(this.configWorlds.getConfigurationSection("worlds").getKeys(false));
|
||||
Map<String, MVWorld> newWorldsFromTheConfig = new HashMap<String, MVWorld>();
|
||||
while (!worldKeys.isEmpty()) {
|
||||
String key = worldKeys.pop();
|
||||
String path = "worlds" + SEPARATOR + key;
|
||||
Object obj = this.configWorlds.get(path);
|
||||
if ((obj != null) && (obj instanceof MVWorld)) {
|
||||
String worldName = key.replaceAll(String.valueOf(SEPARATOR), ".");
|
||||
if (this.worldsFromTheConfig.containsKey(worldName)) {
|
||||
// Object-Recycling :D
|
||||
MVWorld oldMVWorld = (MVWorld) this.worlds.get(worldName);
|
||||
oldMVWorld.copyValues((MVWorld) obj);
|
||||
newWorldsFromTheConfig.put(worldName, oldMVWorld);
|
||||
} else {
|
||||
// we have to use a new one
|
||||
World cbworld = this.plugin.getServer().getWorld(worldName);
|
||||
MVWorld mvworld = (MVWorld) obj;
|
||||
if (cbworld != null)
|
||||
mvworld.init(cbworld, this.plugin);
|
||||
newWorldsFromTheConfig.put(worldName, mvworld);
|
||||
}
|
||||
} else if (this.configWorlds.isConfigurationSection(path)) {
|
||||
ConfigurationSection section = this.configWorlds.getConfigurationSection(path);
|
||||
Set<String> subkeys = section.getKeys(false);
|
||||
for (String subkey : subkeys) {
|
||||
worldKeys.push(key + SEPARATOR + subkey);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.worldsFromTheConfig = newWorldsFromTheConfig;
|
||||
this.worlds.keySet().retainAll(this.worldsFromTheConfig.keySet());
|
||||
return this.configWorlds;
|
||||
}
|
||||
|
||||
@@ -620,6 +627,11 @@ public class WorldManager implements MVWorldManager {
|
||||
@Override
|
||||
public boolean saveWorldsConfig() {
|
||||
try {
|
||||
this.configWorlds.options().pathSeparator(SEPARATOR);
|
||||
this.configWorlds.set("worlds", null);
|
||||
for (Map.Entry<String, ? extends MultiverseWorld> entry : worldsFromTheConfig.entrySet()) {
|
||||
this.configWorlds.set("worlds" + SEPARATOR + entry.getKey(), entry.getValue());
|
||||
}
|
||||
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
@@ -641,7 +653,9 @@ public class WorldManager implements MVWorldManager {
|
||||
*/
|
||||
@Override
|
||||
public List<String> getUnloadedWorlds() {
|
||||
return this.unloadedWorlds;
|
||||
List<String> allNames = new ArrayList<String>(this.worldsFromTheConfig.keySet());
|
||||
allNames.removeAll(worlds.keySet());
|
||||
return allNames;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An {@link URLShortener} using {@code bit.ly}.
|
||||
*/
|
||||
public class BitlyURLShortener extends HttpAPIClient implements URLShortener {
|
||||
private static final String GENERIC_BITLY_REQUEST_FORMAT = "https://api-ssl.bitly.com/v3/shorten?format=txt&apiKey=%s&login=%s&longUrl=%s";
|
||||
|
||||
// I think it's no problem that these are public
|
||||
private static final String USERNAME = "multiverse2";
|
||||
private static final String API_KEY = "R_9dbff4862a3bc0c4218a7d78cc10d0e0";
|
||||
|
||||
public BitlyURLShortener() {
|
||||
super(String.format(GENERIC_BITLY_REQUEST_FORMAT, API_KEY, USERNAME, "%s"));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String shorten(String longUrl) {
|
||||
try {
|
||||
String result = this.exec(longUrl);
|
||||
if (!result.startsWith("http://j.mp/")) // ... then it's failed :/
|
||||
throw new IOException(result);
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return longUrl; // sorry ...
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* HTTP API-client.
|
||||
*/
|
||||
public abstract class HttpAPIClient {
|
||||
/**
|
||||
* The URL for this API-request.
|
||||
*/
|
||||
protected final String urlFormat;
|
||||
|
||||
public HttpAPIClient(String urlFormat) {
|
||||
this.urlFormat = urlFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes this API-Request.
|
||||
* @param args Format-args.
|
||||
* @return The result (as text).
|
||||
* @throws IOException When the I/O-operation failed.
|
||||
*/
|
||||
protected final String exec(Object... args) throws IOException {
|
||||
|
||||
URLConnection conn = new URL(String.format(this.urlFormat, args)).openConnection();
|
||||
conn.connect();
|
||||
StringBuilder ret = new StringBuilder();
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
while (!reader.ready()); // wait until reader is ready, may not be necessary, SUPPRESS CHECKSTYLE: EmptyStatement
|
||||
|
||||
while (reader.ready()) {
|
||||
ret.append(reader.readLine()).append('\n');
|
||||
}
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
}
|
||||
+16
-19
@@ -1,6 +1,7 @@
|
||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -8,7 +9,6 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Pastes to {@code pastebin.com}.
|
||||
@@ -55,38 +55,35 @@ public class PastebinPasteService implements PasteService {
|
||||
*/
|
||||
@Override
|
||||
public String postData(String encodedData, URL url) throws PasteFailedException {
|
||||
OutputStreamWriter wr = null;
|
||||
BufferedReader rd = null;
|
||||
try {
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setDoOutput(true);
|
||||
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
|
||||
wr = new OutputStreamWriter(conn.getOutputStream());
|
||||
wr.write(encodedData);
|
||||
wr.flush();
|
||||
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
String pastebinUrl = "";
|
||||
while ((line = rd.readLine()) != null) {
|
||||
pastebinUrl = line;
|
||||
}
|
||||
wr.close();
|
||||
rd.close();
|
||||
return pastebinUrl;
|
||||
} catch (Exception e) {
|
||||
throw new PasteFailedException(e);
|
||||
} finally {
|
||||
if (wr != null) {
|
||||
try {
|
||||
wr.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
if (rd != null) {
|
||||
try {
|
||||
rd.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO maybe remove this?
|
||||
private Pattern getURLMatchingPattern() {
|
||||
if (this.isPrivate) {
|
||||
return Pattern.compile(".*http://pastie.org/.*key=([0-9a-z]+).*");
|
||||
} else {
|
||||
return Pattern.compile(".*http://pastie.org/([0-9]+).*");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO maybe remove this?
|
||||
private String formatURL(String pastieID) {
|
||||
return "http://pastie.org/" + (this.isPrivate ? "private/" : "") + pastieID;
|
||||
}
|
||||
}
|
||||
+16
-4
@@ -1,6 +1,7 @@
|
||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -55,14 +56,16 @@ public class PastiePasteService implements PasteService {
|
||||
*/
|
||||
@Override
|
||||
public String postData(String encodedData, URL url) throws PasteFailedException {
|
||||
OutputStreamWriter wr = null;
|
||||
BufferedReader rd = null;
|
||||
try {
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setDoOutput(true);
|
||||
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
|
||||
wr = new OutputStreamWriter(conn.getOutputStream());
|
||||
wr.write(encodedData);
|
||||
wr.flush();
|
||||
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
String pastieUrl = "";
|
||||
Pattern pastiePattern = this.getURLMatchingPattern();
|
||||
@@ -73,11 +76,20 @@ public class PastiePasteService implements PasteService {
|
||||
pastieUrl = this.formatURL(pastieID);
|
||||
}
|
||||
}
|
||||
wr.close();
|
||||
rd.close();
|
||||
return pastieUrl;
|
||||
} catch (Exception e) {
|
||||
throw new PasteFailedException(e);
|
||||
} finally {
|
||||
if (wr != null) {
|
||||
try {
|
||||
wr.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
if (rd != null) {
|
||||
try {
|
||||
rd.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
|
||||
/**
|
||||
* URL-Shortener.
|
||||
*/
|
||||
public interface URLShortener {
|
||||
/**
|
||||
* Shorten an URL.
|
||||
* @param longUrl The long form.
|
||||
* @return The shortened URL.
|
||||
*/
|
||||
String shorten(String longUrl);
|
||||
}
|
||||
@@ -20,9 +20,9 @@ import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
@@ -33,7 +33,7 @@ import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ MultiverseCore.class })
|
||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
||||
public class TestDebugMode {
|
||||
TestInstanceCreator creator;
|
||||
Server mockServer;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
||||
public class TestModifyCommand {
|
||||
TestInstanceCreator creator;
|
||||
Server mockServer;
|
||||
MultiverseCore core;
|
||||
CommandSender mockCommandSender;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
creator = new TestInstanceCreator();
|
||||
assertTrue(creator.setUp());
|
||||
mockServer = creator.getServer();
|
||||
mockCommandSender = creator.getCommandSender();
|
||||
core = creator.getCore();
|
||||
|
||||
// create world
|
||||
assertTrue(core.getMVWorldManager().addWorld("world", Environment.NORMAL, null, null, null, null));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
creator.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetHidden() {
|
||||
Command cmd = mock(Command.class);
|
||||
when(cmd.getName()).thenReturn("mv");
|
||||
|
||||
MultiverseWorld world = core.getMVWorldManager().getMVWorld("world");
|
||||
assertNotNull(world);
|
||||
|
||||
assertFalse(world.isHidden()); // ensure it's not hidden now
|
||||
assertTrue(core.onCommand(mockCommandSender, cmd, "", // run the command
|
||||
new String[] { "modify", "set", "hidden", "true", "world" }));
|
||||
assertTrue(world.isHidden()); // test if it worked
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.internal.verification.VerificationModeFactory;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
||||
public class TestWorldCreation {
|
||||
|
||||
private TestInstanceCreator creator;
|
||||
private MultiverseCore core;
|
||||
private CommandSender mockCommandSender;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.creator = new TestInstanceCreator();
|
||||
assertTrue(this.creator.setUp());
|
||||
this.core = this.creator.getCore();
|
||||
this.mockCommandSender = this.creator.getCommandSender();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
creator.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() {
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
|
||||
// Try to create a world that exists
|
||||
String[] normalArgs = new String[] { "create", "world", "normal" };
|
||||
core.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
verify(mockCommandSender).sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
|
||||
verify(mockCommandSender).sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
|
||||
|
||||
// Try to create a world that is new
|
||||
String[] newArgs = new String[] { "create", "world2", "normal" };
|
||||
core.onCommand(mockCommandSender, mockCommand, "", newArgs);
|
||||
verify(mockCommandSender).sendMessage("Starting creation of world 'world2'...");
|
||||
|
||||
String[] dottedWorld = new String[] { "create", "fish.world", "normal" };
|
||||
core.onCommand(mockCommandSender, mockCommand, "", dottedWorld);
|
||||
verify(mockCommandSender).sendMessage("Starting creation of world 'fish.world'...");
|
||||
verify(mockCommandSender, VerificationModeFactory.times(2)).sendMessage("Complete!");
|
||||
|
||||
// Grab the Config
|
||||
Field worldConfigField = null;
|
||||
ConfigurationSection worldsSection = null;
|
||||
try {
|
||||
worldConfigField = WorldManager.class.getDeclaredField("configWorlds");
|
||||
worldConfigField.setAccessible(true);
|
||||
Configuration rootConfig = (Configuration) worldConfigField.get(this.core.getMVWorldManager());
|
||||
worldsSection = rootConfig.getConfigurationSection("worlds");
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Verify that the world was added to the configs
|
||||
// TODO: Expand this.
|
||||
assertNotNull(worldsSection);
|
||||
assertEquals(2, worldsSection.getKeys(false).size());
|
||||
assertTrue(worldsSection.getKeys(false).contains("world2"));
|
||||
assertTrue(worldsSection.getKeys(false).contains("fish.world"));
|
||||
}
|
||||
}
|
||||
@@ -12,15 +12,17 @@ import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.File;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
@@ -31,10 +33,10 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.weather.ThunderChangeEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.internal.verification.VerificationModeFactory;
|
||||
@@ -42,9 +44,11 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
|
||||
@@ -52,9 +56,8 @@ import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class,
|
||||
WeatherChangeEvent.class, ThunderChangeEvent.class, PlayerChatEvent.class,
|
||||
PlayerJoinEvent.class, PlayerRespawnEvent.class, EntityRegainHealthEvent.class,
|
||||
FoodLevelChangeEvent.class, WorldManager.class })
|
||||
FoodLevelChangeEvent.class, WorldManager.class, PluginDescriptionFile.class })
|
||||
public class TestWorldProperties {
|
||||
|
||||
private TestInstanceCreator creator;
|
||||
private MultiverseCore core;
|
||||
private CommandSender mockCommandSender;
|
||||
@@ -71,7 +74,7 @@ public class TestWorldProperties {
|
||||
private PlayerJoinEvent playerJoinEvent;
|
||||
private PlayerRespawnEvent playerRespawnBed;
|
||||
private PlayerRespawnEvent playerRespawnNormal;
|
||||
private Entity mockEntity;
|
||||
private HumanEntity mockHumanEntity;
|
||||
private EntityRegainHealthEvent entityRegainHealthEvent;
|
||||
private FoodLevelChangeEvent entityFoodLevelChangeEvent;
|
||||
private FoodLevelChangeEvent entityFoodLevelRiseEvent;
|
||||
@@ -90,7 +93,7 @@ public class TestWorldProperties {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws Exception {
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
@@ -128,12 +131,9 @@ public class TestWorldProperties {
|
||||
assertEquals(mvWorld.getName(), mvWorld.getAlias());
|
||||
assertEquals(ChatColor.WHITE, mvWorld.getColor());
|
||||
assertTrue(mvWorld.isPVPEnabled());
|
||||
assertEquals((Object) 1D, (Object) mvWorld.getScaling()); // we're casting this to objects to use
|
||||
// assertEquals(Object,Object) instead of assertEquals(double,double)
|
||||
assertEquals(1D, mvWorld.getScaling(), 0);
|
||||
assertNull(mvWorld.getRespawnToWorld());
|
||||
assertTrue(mvWorld.isWeatherEnabled());
|
||||
World cbWorld = mvWorld.getCBWorld();
|
||||
when(cbWorld.getDifficulty()).thenReturn(Difficulty.NORMAL);
|
||||
assertEquals(Difficulty.NORMAL, mvWorld.getDifficulty());
|
||||
assertTrue(mvWorld.canAnimalsSpawn());
|
||||
assertTrue(mvWorld.canMonstersSpawn());
|
||||
@@ -146,7 +146,7 @@ public class TestWorldProperties {
|
||||
assertTrue(mvWorld.isKeepingSpawnInMemory());
|
||||
assertTrue(mvWorld.getBedRespawn());
|
||||
assertTrue(mvWorld.getAutoLoad());
|
||||
assertEquals(new Location(mvWorld.getCBWorld(), 0, 64, 0), mvWorld.getSpawnLocation());
|
||||
assertEquals(new SpawnLocation(0, 64, 0), mvWorld.getSpawnLocation());
|
||||
|
||||
/* ****************************************** *
|
||||
* Call some events and verify behavior
|
||||
@@ -200,24 +200,21 @@ public class TestWorldProperties {
|
||||
mvWorld.setAlias("alias");
|
||||
assertEquals("alias", mvWorld.getAlias());
|
||||
assertTrue(mvWorld.setColor("BLACK"));
|
||||
ChatColor oldColor = mvWorld.getColor();
|
||||
assertFalse(mvWorld.setColor("INVALID COLOR"));
|
||||
assertEquals(oldColor, mvWorld.getColor());
|
||||
assertEquals(oldColor.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
|
||||
assertEquals(ChatColor.BLACK, mvWorld.getColor());
|
||||
assertEquals(ChatColor.BLACK.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
|
||||
mvWorld.setPVPMode(false);
|
||||
assertEquals(false, mvWorld.isPVPEnabled());
|
||||
assertTrue(mvWorld.setScaling(2D));
|
||||
assertEquals((Object) 2D, (Object) mvWorld.getScaling());
|
||||
assertEquals(2D, mvWorld.getScaling(), 0);
|
||||
assertFalse(mvWorld.setRespawnToWorld("INVALID WORLD"));
|
||||
assertTrue(mvWorld.setRespawnToWorld("world_nether"));
|
||||
assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
|
||||
mvWorld.getRespawnToWorld());
|
||||
mvWorld.setEnableWeather(false);
|
||||
assertEquals(false, mvWorld.isWeatherEnabled());
|
||||
assertTrue(mvWorld.setDifficulty("PEACEFUL"));
|
||||
Difficulty oldDifficulty = mvWorld.getDifficulty();
|
||||
assertFalse(mvWorld.setDifficulty("INVALID DIFFICULTY"));
|
||||
assertEquals(oldDifficulty, mvWorld.getDifficulty());
|
||||
assertTrue(mvWorld.setDifficulty(Difficulty.PEACEFUL));
|
||||
assertEquals(Difficulty.PEACEFUL, mvWorld.getDifficulty());
|
||||
mvWorld.setAllowAnimalSpawn(false);
|
||||
assertEquals(false, mvWorld.canAnimalsSpawn());
|
||||
mvWorld.setAllowMonsterSpawn(false);
|
||||
@@ -225,17 +222,15 @@ public class TestWorldProperties {
|
||||
mvWorld.setCurrency(1);
|
||||
assertEquals(1, mvWorld.getCurrency());
|
||||
mvWorld.setPrice(1D);
|
||||
assertEquals((Object) 1D, (Object) mvWorld.getPrice());
|
||||
assertEquals(1D, mvWorld.getPrice(), 0);
|
||||
mvWorld.setHunger(false);
|
||||
assertEquals(false, mvWorld.getHunger());
|
||||
mvWorld.setAutoHeal(false);
|
||||
assertEquals(false, mvWorld.getAutoHeal());
|
||||
mvWorld.setAdjustSpawn(false);
|
||||
assertEquals(false, mvWorld.getAdjustSpawn());
|
||||
assertTrue(mvWorld.setGameMode("CREATIVE"));
|
||||
GameMode oldGamemode = mvWorld.getGameMode();
|
||||
assertFalse(mvWorld.setGameMode("INVALID GAMEMODE"));
|
||||
assertEquals(oldGamemode, mvWorld.getGameMode());
|
||||
assertTrue(mvWorld.setGameMode(GameMode.CREATIVE));
|
||||
assertEquals(GameMode.CREATIVE, mvWorld.getGameMode());
|
||||
mvWorld.setKeepSpawnInMemory(false);
|
||||
assertEquals(false, mvWorld.isKeepingSpawnInMemory());
|
||||
mvWorld.setBedRespawn(false);
|
||||
@@ -243,7 +238,8 @@ public class TestWorldProperties {
|
||||
mvWorld.setAutoLoad(false);
|
||||
assertEquals(false, mvWorld.getAutoLoad());
|
||||
mvWorld.setSpawnLocation(new Location(mvWorld.getCBWorld(), 1, 1, 1));
|
||||
assertEquals(new Location(mvWorld.getCBWorld(), 1, 1, 1), mvWorld.getSpawnLocation());
|
||||
assertEquals(new SpawnLocation(1, 1, 1), mvWorld.getSpawnLocation());
|
||||
|
||||
|
||||
/* ****************************************** *
|
||||
* Call some events and verify behavior
|
||||
@@ -275,12 +271,13 @@ public class TestWorldProperties {
|
||||
core.getMVConfig().setPrefixChat(false);
|
||||
core.getPlayerListener().playerChat(playerChatEvent);
|
||||
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
|
||||
mvWorld.setHidden(true); // reset hidden-state
|
||||
|
||||
// call player join events
|
||||
core.getPlayerListener().playerJoin(playerJoinEvent);
|
||||
verify(mockPlayer, never()).teleport(any(Location.class));
|
||||
core.getPlayerListener().playerJoin(playerNewJoinEvent);
|
||||
verify(mockNewPlayer).teleport(new Location(mvWorld.getCBWorld(), 1, 1, 1));
|
||||
verify(mockNewPlayer).teleport(new SpawnLocation(1, 1, 1));
|
||||
|
||||
// call player respawn events
|
||||
core.getPlayerListener().playerRespawn(playerRespawnBed);
|
||||
@@ -293,6 +290,44 @@ public class TestWorldProperties {
|
||||
core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
|
||||
// autoheal is off so something should happen
|
||||
verify(entityRegainHealthEvent).setCancelled(true);
|
||||
|
||||
|
||||
/* ****************************************** *
|
||||
* Test saving/loading
|
||||
* ****************************************** */
|
||||
assertTrue(core.saveMVConfigs());
|
||||
// change a value here
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml"));
|
||||
MVWorld worldObj = (MVWorld) config.get("worlds.world");
|
||||
assertTrue(worldObj.setColor("GREEN"));
|
||||
config.set("worlds.world", worldObj);
|
||||
config.save(new File(core.getDataFolder(), "worlds.yml"));
|
||||
// load
|
||||
core.loadConfigs();
|
||||
|
||||
mvWorld = worldManager.getMVWorld("world");
|
||||
assertEquals(true, mvWorld.isHidden());
|
||||
assertEquals("alias", mvWorld.getAlias());
|
||||
assertEquals(ChatColor.GREEN, mvWorld.getColor());
|
||||
assertEquals(ChatColor.GREEN.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
|
||||
assertEquals(false, mvWorld.isPVPEnabled());
|
||||
assertEquals(2D, mvWorld.getScaling(), 0);
|
||||
assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
|
||||
mvWorld.getRespawnToWorld());
|
||||
assertEquals(false, mvWorld.isWeatherEnabled());
|
||||
assertEquals(Difficulty.PEACEFUL, mvWorld.getDifficulty());
|
||||
assertEquals(false, mvWorld.canAnimalsSpawn());
|
||||
assertEquals(false, mvWorld.canMonstersSpawn());
|
||||
assertEquals(1, mvWorld.getCurrency());
|
||||
assertEquals(1D, mvWorld.getPrice(), 0);
|
||||
assertEquals(false, mvWorld.getHunger());
|
||||
assertEquals(false, mvWorld.getAutoHeal());
|
||||
assertEquals(false, mvWorld.getAdjustSpawn());
|
||||
assertEquals(GameMode.CREATIVE, mvWorld.getGameMode());
|
||||
assertEquals(false, mvWorld.isKeepingSpawnInMemory());
|
||||
assertEquals(false, mvWorld.getBedRespawn());
|
||||
assertEquals(false, mvWorld.getAutoLoad());
|
||||
assertEquals(new SpawnLocation(1, 1, 1), mvWorld.getSpawnLocation());
|
||||
}
|
||||
|
||||
public void createEvents(MultiverseWorld mvWorld) {
|
||||
@@ -308,6 +343,7 @@ public class TestWorldProperties {
|
||||
mockPlayer = mock(Player.class);
|
||||
when(mockPlayer.getWorld()).thenReturn(mvWorld.getCBWorld());
|
||||
when(mockPlayer.hasPlayedBefore()).thenReturn(true);
|
||||
when(mockPlayer.hasPermission("multiverse.access.world")).thenReturn(true);
|
||||
playerChatEvent = PowerMockito.mock(PlayerChatEvent.class);
|
||||
when(playerChatEvent.getPlayer()).thenReturn(mockPlayer);
|
||||
when(playerChatEvent.getFormat()).thenReturn("format");
|
||||
@@ -326,17 +362,17 @@ public class TestWorldProperties {
|
||||
when(playerRespawnNormal.getPlayer()).thenReturn(mockPlayer);
|
||||
when(playerRespawnNormal.isBedSpawn()).thenReturn(false);
|
||||
//// Entity events
|
||||
mockEntity = mock(Entity.class);
|
||||
mockHumanEntity = mock(HumanEntity.class);
|
||||
// entity regain health
|
||||
entityRegainHealthEvent = PowerMockito.mock(EntityRegainHealthEvent.class);
|
||||
when(entityRegainHealthEvent.getRegainReason()).thenReturn(RegainReason.REGEN);
|
||||
when(mockEntity.getLocation()).thenReturn(new Location(mvWorld.getCBWorld(), 0, 0, 0));
|
||||
when(entityRegainHealthEvent.getEntity()).thenReturn(mockEntity);
|
||||
when(mockHumanEntity.getLocation()).thenReturn(new Location(mvWorld.getCBWorld(), 0, 0, 0));
|
||||
when(entityRegainHealthEvent.getEntity()).thenReturn(mockHumanEntity);
|
||||
// entity food level change event
|
||||
entityFoodLevelChangeEvent = PowerMockito.mock(FoodLevelChangeEvent.class);
|
||||
// this won't do anything since we're not mocking a player,
|
||||
// but the plugin should be able to handle this!
|
||||
when(entityFoodLevelChangeEvent.getEntity()).thenReturn(mockEntity);
|
||||
when(entityFoodLevelChangeEvent.getEntity()).thenReturn(mockHumanEntity);
|
||||
entityFoodLevelRiseEvent = PowerMockito.mock(FoodLevelChangeEvent.class);
|
||||
when(mockPlayer.getFoodLevel()).thenReturn(2);
|
||||
when(entityFoodLevelRiseEvent.getEntity()).thenReturn(mockPlayer);
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
||||
public class TestWorldPurger {
|
||||
TestInstanceCreator creator;
|
||||
MultiverseCore core;
|
||||
WorldPurger purger;
|
||||
|
||||
MultiverseWorld mvWorld;
|
||||
World cbworld;
|
||||
|
||||
Sheep sheep;
|
||||
Zombie zombie;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
creator = new TestInstanceCreator();
|
||||
assertTrue(creator.setUp());
|
||||
core = creator.getCore();
|
||||
purger = core.getMVWorldManager().getTheWorldPurger();
|
||||
core.getMVConfig().setGlobalDebug(3);
|
||||
mvWorld = mock(MultiverseWorld.class);
|
||||
cbworld = mock(World.class);
|
||||
when(mvWorld.getCBWorld()).thenReturn(cbworld);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
creator.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
// test 1: purge ALL without negations ==> both should be removed
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ALL"), false, false);
|
||||
verify(sheep).remove();
|
||||
verify(zombie).remove();
|
||||
|
||||
// test 2: purge ALL with one negation ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ALL"), false, true);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 3: purge ALL with both negations ==> everybody should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ALL"), true, true);
|
||||
verify(sheep, never()).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 4: purge ANIMALS without negations ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ANIMALS"), false, false);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 5: purge MONSTERS with one negation ==> nobody should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("MONSTERS"), true, false);
|
||||
verify(sheep).remove();
|
||||
verify(zombie).remove();
|
||||
|
||||
// test 6: purge MONSTERS both negations ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("MONSTERS"), true, true);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 7: purge SHEEP without negations ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("SHEEP"), false, false);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 8: purge SHEEP with one negation ==> nobody should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("SHEEP"), false, true);
|
||||
verify(sheep).remove();
|
||||
verify(zombie).remove();
|
||||
|
||||
// test 9: purge ZOMBIE with both negations ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ZOMBIE"), true, true);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// I like sheep.
|
||||
}
|
||||
|
||||
private void createAnimals() {
|
||||
sheep = mock(Sheep.class);
|
||||
when(sheep.getType()).thenReturn(EntityType.SHEEP);
|
||||
zombie = mock(Zombie.class);
|
||||
when(zombie.getType()).thenReturn(EntityType.ZOMBIE);
|
||||
when(cbworld.getEntities()).thenReturn(Arrays.asList((Entity) sheep, (Entity) zombie));
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -34,7 +35,7 @@ import static junit.framework.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class })
|
||||
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class, PluginDescriptionFile.class })
|
||||
public class TestWorldStuff {
|
||||
|
||||
private TestInstanceCreator creator;
|
||||
@@ -234,13 +235,13 @@ public class TestWorldStuff {
|
||||
// Now fail one.
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "mode", "fish", "world" });
|
||||
try {
|
||||
verify(mockCommandSender).sendMessage(mainWorld.getProperty("mode", Object.class).getHelp());
|
||||
verify(mockCommandSender).sendMessage(ChatColor.RED + mainWorld.getPropertyHelp("mode"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
fail("Mode property did not exist.");
|
||||
}
|
||||
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "blah", "fish", "world" });
|
||||
verify(mockCommandSender).sendMessage(ChatColor.RED + "Sorry, You can't set: '"+ChatColor.GRAY+ "blah" + ChatColor.RED + "'");
|
||||
verify(mockCommandSender).sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + "blah" + ChatColor.RED + "'");
|
||||
}
|
||||
|
||||
private void createInitialWorlds(Plugin plugin, Command command) {
|
||||
|
||||
@@ -1,330 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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.test.utils;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*/
|
||||
public class MockBlock implements Block{
|
||||
private Material type;
|
||||
private Location location;
|
||||
|
||||
|
||||
public MockBlock(Location l, Material type) {
|
||||
this.type = type;
|
||||
this.location = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public byte getData() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getFace(BlockFace face) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getFace(BlockFace face, int distance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(int modX, int modY, int modZ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(BlockFace face) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(BlockFace face, int distance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Material getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getTypeId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public byte getLightLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getLightFromSky() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getLightFromBlocks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.location.getWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getX() {
|
||||
return this.location.getBlockX();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getY() {
|
||||
return this.location.getBlockY();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getZ() {
|
||||
return this.location.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Chunk getChunk() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setData(byte data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(byte data, boolean applyPhyiscs) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setType(Material type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setTypeId(int type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTypeId(int type, boolean applyPhysics) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTypeIdAndData(int type, byte data, boolean applyPhyiscs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BlockFace getFace(Block block) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BlockState getState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Biome getBiome() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockPowered() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockIndirectlyPowered() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockFacePowered(BlockFace face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getBlockPower(BlockFace face) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getBlockPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.type == Material.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isLiquid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public double getTemperature() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public double getHumidity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public PistonMoveReaction getPistonMoveReaction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakNaturally() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakNaturally(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getDrops() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getDrops(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,9 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -28,6 +30,10 @@ public class MockWorldFactory {
|
||||
|
||||
private static final Map<String, World> createdWorlds = new HashMap<String, World>();
|
||||
|
||||
private static final Map<World, Boolean> pvpStates = new WeakHashMap<World, Boolean>();
|
||||
private static final Map<World, Boolean> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>();
|
||||
private static final Map<World, Difficulty> difficultyStates = new WeakHashMap<World, Difficulty>();
|
||||
|
||||
private MockWorldFactory() {
|
||||
}
|
||||
|
||||
@@ -38,10 +44,59 @@ public class MockWorldFactory {
|
||||
private static World basics(String world, World.Environment env, WorldType type) {
|
||||
World mockWorld = mock(World.class);
|
||||
when(mockWorld.getName()).thenReturn(world);
|
||||
when(mockWorld.getPVP()).thenAnswer(new Answer<Boolean>() {
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!pvpStates.containsKey(w))
|
||||
pvpStates.put(w, true); // default value
|
||||
return pvpStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
pvpStates.put((World) invocation.getMock(), (Boolean) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setPVP(anyBoolean());
|
||||
when(mockWorld.getKeepSpawnInMemory()).thenAnswer(new Answer<Boolean>() {
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!keepSpawnInMemoryStates.containsKey(w))
|
||||
keepSpawnInMemoryStates.put(w, true); // default value
|
||||
return keepSpawnInMemoryStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
keepSpawnInMemoryStates.put((World) invocation.getMock(), (Boolean) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setKeepSpawnInMemory(anyBoolean());
|
||||
when(mockWorld.getDifficulty()).thenAnswer(new Answer<Difficulty>() {
|
||||
@Override
|
||||
public Difficulty answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!difficultyStates.containsKey(w))
|
||||
difficultyStates.put(w, Difficulty.NORMAL); // default value
|
||||
return difficultyStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
difficultyStates.put((World) invocation.getMock(), (Difficulty) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setDifficulty(any(Difficulty.class));
|
||||
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||
when(mockWorld.getWorldType()).thenReturn(type);
|
||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||
@Override
|
||||
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (!(invocation.getMock() instanceof World))
|
||||
return null;
|
||||
@@ -51,6 +106,7 @@ public class MockWorldFactory {
|
||||
}
|
||||
});
|
||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||
@Override
|
||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||
Location loc;
|
||||
try {
|
||||
@@ -85,6 +141,7 @@ public class MockWorldFactory {
|
||||
when(mockWorld.getWorldType()).thenReturn(type);
|
||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||
@Override
|
||||
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (!(invocation.getMock() instanceof World))
|
||||
return null;
|
||||
@@ -94,6 +151,7 @@ public class MockWorldFactory {
|
||||
}
|
||||
});
|
||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||
@Override
|
||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||
Location loc;
|
||||
try {
|
||||
|
||||
@@ -7,18 +7,14 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
import com.onarandombox.MultiverseCore.utils.FileUtils;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
@@ -35,14 +31,17 @@ import org.mockito.Matchers;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.MockGateway;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
import com.onarandombox.MultiverseCore.utils.FileUtils;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class TestInstanceCreator {
|
||||
private MultiverseCore core;
|
||||
@@ -58,14 +57,17 @@ public class TestInstanceCreator {
|
||||
pluginDirectory.mkdirs();
|
||||
Assert.assertTrue(pluginDirectory.exists());
|
||||
|
||||
MockGateway.MOCK_STANDARD_METHODS = false;
|
||||
|
||||
core = PowerMockito.spy(new MultiverseCore());
|
||||
|
||||
// Let's let all MV files go to bin/test
|
||||
doReturn(pluginDirectory).when(core).getDataFolder();
|
||||
|
||||
// Return a fake PDF file.
|
||||
PluginDescriptionFile pdf = new PluginDescriptionFile("Multiverse-Core", "2.2-Test",
|
||||
"com.onarandombox.MultiverseCore.MultiverseCore");
|
||||
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Multiverse-Core", "2.2-Test",
|
||||
"com.onarandombox.MultiverseCore.MultiverseCore"));
|
||||
when(pdf.getAuthors()).thenReturn(new ArrayList<String>());
|
||||
doReturn(pdf).when(core).getDescription();
|
||||
doReturn(true).when(core).isEnabled();
|
||||
core.setServerFolder(serverDirectory);
|
||||
@@ -99,6 +101,7 @@ public class TestInstanceCreator {
|
||||
|
||||
// Give the server some worlds
|
||||
when(mockServer.getWorld(anyString())).thenAnswer(new Answer<World>() {
|
||||
@Override
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
String arg;
|
||||
try {
|
||||
@@ -111,6 +114,7 @@ public class TestInstanceCreator {
|
||||
});
|
||||
|
||||
when(mockServer.getWorlds()).thenAnswer(new Answer<List<World>>() {
|
||||
@Override
|
||||
public List<World> answer(InvocationOnMock invocation) throws Throwable {
|
||||
return MockWorldFactory.getWorlds();
|
||||
}
|
||||
@@ -120,6 +124,7 @@ public class TestInstanceCreator {
|
||||
|
||||
when(mockServer.createWorld(Matchers.isA(WorldCreator.class))).thenAnswer(
|
||||
new Answer<World>() {
|
||||
@Override
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
WorldCreator arg;
|
||||
try {
|
||||
@@ -142,6 +147,7 @@ public class TestInstanceCreator {
|
||||
BukkitScheduler mockScheduler = mock(BukkitScheduler.class);
|
||||
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class), anyLong())).
|
||||
thenAnswer(new Answer<Integer>() {
|
||||
@Override
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
Runnable arg;
|
||||
try {
|
||||
@@ -154,6 +160,7 @@ public class TestInstanceCreator {
|
||||
}});
|
||||
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class))).
|
||||
thenAnswer(new Answer<Integer>() {
|
||||
@Override
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
Runnable arg;
|
||||
try {
|
||||
@@ -200,6 +207,7 @@ public class TestInstanceCreator {
|
||||
commandSenderLogger.setParent(Util.logger);
|
||||
commandSender = mock(CommandSender.class);
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
commandSenderLogger.info(ChatColor.stripColor((String) invocation.getArguments()[0]));
|
||||
return null;
|
||||
@@ -248,6 +256,8 @@ public class TestInstanceCreator {
|
||||
return false;
|
||||
}
|
||||
|
||||
core.onDisable();
|
||||
|
||||
FileUtils.deleteFolder(serverDirectory);
|
||||
MockWorldFactory.clearWorlds();
|
||||
|
||||
|
||||
Reference in new issue
Block a user