Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57b3370381 | ||
|
|
9d213fbc0a | ||
|
|
0c638035f2 | ||
|
|
fb6a031860 | ||
|
|
703707a39b | ||
|
|
0b7b91a081 | ||
|
|
21b997c1a2 | ||
|
|
7031e9e58b | ||
|
|
322acbc636 | ||
|
|
256d4b0abd | ||
|
|
88088548f8 | ||
|
|
affc96f2e2 | ||
|
|
f3830390f6 | ||
|
|
8b224349e6 | ||
|
|
b51e26bcf1 | ||
|
|
49ffb4dcec | ||
|
|
a66a5eaeb3 | ||
|
|
ba6f580fd8 | ||
|
|
e6c36be019 | ||
|
|
3e4b042de8 | ||
|
|
451955f858 | ||
|
|
8e5d96309f | ||
|
|
970692d228 | ||
|
|
91a5d6c1c5 | ||
|
|
7668d14613 | ||
|
|
38ce30f981 | ||
|
|
abb58b0563 | ||
|
|
22a7c5ae94 | ||
|
|
303bbc317b | ||
|
|
3531bd6432 |
No files matched your search
@@ -1,5 +0,0 @@
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk6
|
||||
notifications:
|
||||
email: false
|
||||
@@ -104,6 +104,7 @@
|
||||
</module>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="RightCurly"/>
|
||||
<module name="DoubleCheckedLocking"/>
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
<module name="HiddenField">
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
<url>http://repo.mcstats.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<!-- Required for Vault -->
|
||||
<!--repository>
|
||||
<repository>
|
||||
<id>herocraft</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything/</url>
|
||||
</repository-->
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
@@ -134,7 +134,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>2.10</version>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<enableRulesSummary>true</enableRulesSummary>
|
||||
<configLocation>${project.basedir}/config/mv_checks.xml</configLocation>
|
||||
@@ -220,45 +220,17 @@
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>apache-commons-io</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>org.apache.commons:commons-io</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons</pattern>
|
||||
<shadedPattern>org.apache.commons.multiverse</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Bukkit Dependency -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.4.5-R0.2</version>
|
||||
<version>1.3.2-R2.1-SNAPSHOT</version>
|
||||
<!-- If you want the lates, use this -->
|
||||
<!-- <version>LATEST</version> -->
|
||||
<type>jar</type>
|
||||
@@ -276,7 +248,7 @@
|
||||
<dependency>
|
||||
<groupId>me.main__.util</groupId>
|
||||
<artifactId>SerializationConfig</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.6c</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -285,14 +257,14 @@
|
||||
<dependency>
|
||||
<groupId>com.fernferret.allpay</groupId>
|
||||
<artifactId>AllPay</artifactId>
|
||||
<version>13</version>
|
||||
<version>10</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.20</version>
|
||||
<version>1.2.19-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -10,8 +10,7 @@ package com.onarandombox.MultiverseCore;
|
||||
import buscript.Buscript;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.fernferret.allpay.AllPay;
|
||||
import com.fernferret.allpay.commons.GenericBank;
|
||||
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
import com.onarandombox.MultiverseCore.api.BlockSafety;
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.api.LocationManipulation;
|
||||
@@ -31,8 +30,6 @@ 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.GameruleCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GamerulesCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GeneratorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.HelpCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ImportCommand;
|
||||
@@ -64,15 +61,22 @@ 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.MVAsyncPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVMapListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
|
||||
import com.onarandombox.MultiverseCore.localization.LazyLocaleMessageProvider;
|
||||
import com.onarandombox.MultiverseCore.localization.LocalizationLoadingException;
|
||||
import com.onarandombox.MultiverseCore.localization.MessageProvider;
|
||||
import com.onarandombox.MultiverseCore.localization.MessageProviding;
|
||||
import com.onarandombox.MultiverseCore.localization.NoSuchLocalizationException;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
import com.onarandombox.MultiverseCore.localization.SimpleMessageProvider;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.MVMessaging;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
@@ -80,15 +84,11 @@ 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.UnsafeCallWrapper;
|
||||
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -111,6 +111,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
@@ -118,13 +119,14 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* The implementation of the Multiverse-{@link Core}.
|
||||
*/
|
||||
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, MessageProviding {
|
||||
private static final int PROTOCOL = 18;
|
||||
// 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);
|
||||
private MessageProvider messageProvider = new SimpleMessageProvider(this);
|
||||
// TODO please let's make this non-static
|
||||
private volatile MultiverseCoreConfiguration config;
|
||||
|
||||
@@ -219,7 +221,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private BlockSafety blockSafety;
|
||||
private LocationManipulation locationManipulation;
|
||||
private SafeTTeleporter safeTTeleporter;
|
||||
private UnsafeCallWrapper unsafeCallWrapper;
|
||||
|
||||
private File serverFolder = new File(System.getProperty("user.dir"));
|
||||
|
||||
@@ -228,7 +229,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// Register our config
|
||||
SerializationConfig.registerAll(MultiverseCoreConfiguration.class);
|
||||
// Register our world
|
||||
SerializationConfig.registerAll(WorldProperties.class);
|
||||
SerializationConfig.registerAll(MVWorld.class);
|
||||
// Create our DataFolder
|
||||
getDataFolder().mkdirs();
|
||||
// Setup our Debug Log
|
||||
@@ -240,7 +241,16 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.locationManipulation = new SimpleLocationManipulation();
|
||||
// Setup our SafeTTeleporter
|
||||
this.safeTTeleporter = new SimpleSafeTTeleporter(this);
|
||||
this.unsafeCallWrapper = new UnsafeCallWrapper(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @deprecated This is deprecated.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public FileConfiguration getMVConfiguration() {
|
||||
return this.multiverseConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +273,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.messaging = new MVMessaging();
|
||||
this.messaging = new MVMessaging(this);
|
||||
this.banker = new AllPay(this, LOG_TAG + " ");
|
||||
this.vaultHandler = new VaultHandler(this);
|
||||
// Load the defaultWorldGenerators
|
||||
@@ -293,6 +303,25 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// this function will be called every time a plugin registers a new envtype with MV
|
||||
// Setup & Load our Configuration files.
|
||||
loadConfigs();
|
||||
try {
|
||||
Locale l = (this.config.getLocale() == null) ? Locale.getDefault() : this.config.getLocale();
|
||||
if (this.messageProvider instanceof LazyLocaleMessageProvider)
|
||||
((LazyLocaleMessageProvider)this.messageProvider).loadLocale(l);
|
||||
this.messageProvider.setLocale(l);
|
||||
} catch (NoSuchLocalizationException e) {
|
||||
if (this.config.getLocale() != null)
|
||||
this.log(Level.SEVERE, String.format(
|
||||
"Multiverse couldn't find any translations for the selected locale '%s'. '%s' will be used instead.",
|
||||
this.config.getLocale(), this.messageProvider.getLocale()));
|
||||
} catch (LocalizationLoadingException e) {
|
||||
this.log(Level.SEVERE, String.format("Failed to load the selected locale '%s'. '%s' will be used instead.",
|
||||
this.config.getLocale(), this.messageProvider.getLocale()));
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.log(Level.SEVERE, e.getMessage());
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (this.multiverseConfig != null) {
|
||||
Logging.setDebugLevel(getMVConfig().getGlobalDebug());
|
||||
Logging.setShowingConfig(!getMVConfig().getSilentStart());
|
||||
@@ -459,7 +488,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
pm.registerEvents(this.pluginListener, this);
|
||||
pm.registerEvents(this.weatherListener, this);
|
||||
pm.registerEvents(this.portalListener, this);
|
||||
pm.registerEvents(new MVMapListener(this), this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -564,13 +593,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
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 WorldProperties) {
|
||||
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
|
||||
WorldProperties world = new WorldProperties(Collections.EMPTY_MAP);
|
||||
MVWorld world = new MVWorld(Collections.EMPTY_MAP);
|
||||
ConfigurationSection section = (ConfigurationSection) entry.getValue();
|
||||
|
||||
// migrate animals and monsters
|
||||
@@ -640,9 +669,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
|
||||
// migrate gamemode
|
||||
if (section.isString("gamemode")) {
|
||||
final GameMode gameMode = GameMode.valueOf(section.getString("gamemode").toUpperCase());
|
||||
if (gameMode != null) {
|
||||
world.setGameMode(gameMode);
|
||||
try {
|
||||
world.setPropertyValue("gamemode", section.getString("gamemode"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,8 +694,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// migrate portalform
|
||||
if (section.isString("portalform")) {
|
||||
try {
|
||||
world.setProperty("portalform", section.getString("portalform"), true);
|
||||
} catch (NoSuchPropertyException e) {
|
||||
world.setPropertyValue("portalform", section.getString("portalform"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
}
|
||||
}
|
||||
@@ -673,8 +703,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// migrate environment
|
||||
if (section.isString("environment")) {
|
||||
try {
|
||||
world.setProperty("environment", section.getString("environment"), true);
|
||||
} catch (NoSuchPropertyException e) {
|
||||
world.setPropertyValue("environment", section.getString("environment"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
}
|
||||
}
|
||||
@@ -712,7 +742,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// migrate spawn
|
||||
if (section.isConfigurationSection("spawn")) {
|
||||
ConfigurationSection spawnSect = section.getConfigurationSection("spawn");
|
||||
Location spawnLoc = new NullLocation();
|
||||
Location spawnLoc = world.getSpawnLocation();
|
||||
if (spawnSect.isDouble("yaw"))
|
||||
spawnLoc.setYaw((float) spawnSect.getDouble("yaw"));
|
||||
if (spawnSect.isDouble("pitch"))
|
||||
@@ -727,19 +757,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
world.setSpawnLocation(spawnLoc);
|
||||
}
|
||||
|
||||
// migrate difficulty
|
||||
if (section.isString("difficulty")) {
|
||||
final Difficulty difficulty = Difficulty.valueOf(section.getString("difficulty").toUpperCase());
|
||||
if (difficulty != null) {
|
||||
world.setDifficulty(difficulty);
|
||||
}
|
||||
}
|
||||
|
||||
// migrate keepspawninmemory
|
||||
if (section.isBoolean("keepspawninmemory")) {
|
||||
world.setKeepSpawnInMemory(section.getBoolean("keepspawninmemory"));
|
||||
}
|
||||
|
||||
newValues.put(entry.getKey(), world);
|
||||
wasChanged = true;
|
||||
} else {
|
||||
@@ -818,8 +835,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.commandHandler.registerCommand(new GeneratorCommand(this));
|
||||
this.commandHandler.registerCommand(new CheckCommand(this));
|
||||
this.commandHandler.registerCommand(new ScriptCommand(this));
|
||||
this.commandHandler.registerCommand(new GameruleCommand(this));
|
||||
this.commandHandler.registerCommand(new GamerulesCommand(this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -871,7 +886,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
if (!this.isEnabled()) {
|
||||
sender.sendMessage("This plugin is Disabled!");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CH_PLUGIN_DISABLED);
|
||||
return true;
|
||||
}
|
||||
ArrayList<String> allArgs = new ArrayList<String>(Arrays.asList(args));
|
||||
@@ -880,11 +895,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
return this.commandHandler.locateAndRunCommand(sender, allArgs, getMVConfig().getDisplayPermErrors());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sender.sendMessage(ChatColor.RED + "An internal error occurred when attempting to perform this command.");
|
||||
if (sender.isOp())
|
||||
sender.sendMessage(ChatColor.RED + "Details were printed to the server console and logs, please add that to your bug report.");
|
||||
else
|
||||
sender.sendMessage(ChatColor.RED + "Try again and contact the server owner or an admin if this problem persists.");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CH_INTERNAL_ERROR);
|
||||
this.messaging.sendMessage(sender, sender.isOp() ? MultiverseMessage.CH_ADMIN_DEBUG : MultiverseMessage.CH_USER_DEBUG);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -916,7 +928,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
* standard Server Console.
|
||||
*
|
||||
* @param level The Log-{@link Level}
|
||||
* @param msg The message
|
||||
* @param msg The message
|
||||
*
|
||||
* @deprecated Replaced by {@link Logging}. Please refrain from using this from a third party plugin as the
|
||||
* messages will appear to originate from Multiverse-Core.
|
||||
@@ -976,8 +988,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
* @param worldName The name of the invalid world
|
||||
*/
|
||||
public void showNotMVWorldMessage(CommandSender sender, String worldName) {
|
||||
sender.sendMessage("Multiverse doesn't know about " + ChatColor.DARK_AQUA + worldName + ChatColor.WHITE + " yet.");
|
||||
sender.sendMessage("Type " + ChatColor.DARK_AQUA + "/mv import ?" + ChatColor.WHITE + " for help!");
|
||||
// TODO remove this method because we can now send this message in one line
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.GENERIC_NOT_MV_WORLD, worldName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1214,6 +1226,25 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
return this.anchorManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public MessageProvider getMessageProvider() {
|
||||
return messageProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setMessageProvider(MessageProvider provider) {
|
||||
if (provider == null)
|
||||
throw new IllegalArgumentException("The new provider can't be null!");
|
||||
|
||||
messageProvider = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -1227,9 +1258,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
*/
|
||||
@Override
|
||||
public void setBlockSafety(BlockSafety bs) {
|
||||
if (bs == null) {
|
||||
throw new NullPointerException("block safety may not be null.");
|
||||
}
|
||||
this.blockSafety = bs;
|
||||
}
|
||||
|
||||
@@ -1288,8 +1316,4 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
public Buscript getScriptAPI() {
|
||||
return buscript;
|
||||
}
|
||||
|
||||
public UnsafeCallWrapper getUnsafeCallWrapper() {
|
||||
return this.unsafeCallWrapper;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import com.dumptruckman.minecraft.util.*;
|
||||
import com.onarandombox.MultiverseCore.api.*;
|
||||
import me.main__.util.SerializationConfig.*;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.configuration.LocaleSerializor;
|
||||
|
||||
import java.util.*;
|
||||
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Our configuration.
|
||||
@@ -61,10 +65,8 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
private volatile String firstspawnworld;
|
||||
@Property
|
||||
private volatile int teleportcooldown;
|
||||
@Property
|
||||
private volatile boolean defaultportalsearch;
|
||||
@Property
|
||||
private volatile int portalsearchradius;
|
||||
@Property(serializor = LocaleSerializor.class)
|
||||
private volatile Locale locale;
|
||||
|
||||
public MultiverseCoreConfiguration() {
|
||||
super();
|
||||
@@ -93,8 +95,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
teleportcooldown = 1000;
|
||||
this.version = 2.9;
|
||||
silentstart = false;
|
||||
defaultportalsearch = false;
|
||||
portalsearchradius = 128;
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
}
|
||||
|
||||
@@ -283,6 +283,16 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
return this.useasyncchat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSilentStart(boolean silentStart) {
|
||||
Logging.setShowingConfig(!silentStart);
|
||||
@@ -293,24 +303,4 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
public boolean getSilentStart() {
|
||||
return silentstart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseDefaultPortalSearch(boolean useDefaultPortalSearch) {
|
||||
defaultportalsearch = useDefaultPortalSearch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsingDefaultPortalSearch() {
|
||||
return defaultportalsearch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPortalSearchRadius(int searchRadius) {
|
||||
this.portalsearchradius = searchRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPortalSearchRadius() {
|
||||
return portalsearchradius;
|
||||
}
|
||||
}
|
||||
@@ -1,638 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
|
||||
import com.onarandombox.MultiverseCore.configuration.EntryFee;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnSettings;
|
||||
import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
|
||||
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
import me.main__.util.SerializationConfig.Serializor;
|
||||
import me.main__.util.SerializationConfig.Validator;
|
||||
import me.main__.util.SerializationConfig.VirtualProperty;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/*
|
||||
* This is a property class, I think we don't need that much javadoc.
|
||||
* BEGIN CHECKSTYLE-SUPPRESSION: Javadoc
|
||||
*/
|
||||
|
||||
@SerializableAs("MVWorld")
|
||||
public class WorldProperties extends SerializationConfig {
|
||||
|
||||
private static final Map<String, String> PROPERTY_ALIASES;
|
||||
|
||||
static {
|
||||
PROPERTY_ALIASES = new HashMap<String, String>();
|
||||
PROPERTY_ALIASES.put("curr", "currency");
|
||||
PROPERTY_ALIASES.put("scaling", "scale");
|
||||
PROPERTY_ALIASES.put("aliascolor", "color");
|
||||
PROPERTY_ALIASES.put("heal", "autoHeal");
|
||||
PROPERTY_ALIASES.put("storm", "allowWeather");
|
||||
PROPERTY_ALIASES.put("weather", "allowWeather");
|
||||
PROPERTY_ALIASES.put("spawnmemory", "keepSpawnInMemory");
|
||||
PROPERTY_ALIASES.put("memory", "keepSpawnInMemory");
|
||||
PROPERTY_ALIASES.put("mode", "gameMode");
|
||||
PROPERTY_ALIASES.put("diff", "difficulty");
|
||||
PROPERTY_ALIASES.put("spawnlocation", "spawn");
|
||||
PROPERTY_ALIASES.put("limit", "playerLimit");
|
||||
PROPERTY_ALIASES.put("animals", "spawning.animals.spawn");
|
||||
PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn");
|
||||
PROPERTY_ALIASES.put("animalsrate", "spawning.animals.spawnrate");
|
||||
PROPERTY_ALIASES.put("monstersrate", "spawning.monsters.spawnrate");
|
||||
PROPERTY_ALIASES.put("flight", "allowFlight");
|
||||
PROPERTY_ALIASES.put("fly", "allowFlight");
|
||||
PROPERTY_ALIASES.put("allowfly", "allowFlight");
|
||||
}
|
||||
|
||||
public WorldProperties(Map<String, Object> values) {
|
||||
super(values);
|
||||
}
|
||||
|
||||
public WorldProperties() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WorldProperties(final boolean fixSpawn, final Environment environment) {
|
||||
super();
|
||||
if (!fixSpawn) {
|
||||
this.adjustSpawn = false;
|
||||
}
|
||||
setScaling(getDefaultScale(environment));
|
||||
}
|
||||
|
||||
void setMVWorld(MVWorld world) {
|
||||
registerObjectUsing(world);
|
||||
registerGlobalValidator(new WorldPropertyValidator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the color-property.
|
||||
*/
|
||||
private static final class EnumPropertySerializor<T extends Enum<T>> implements Serializor<T, String> {
|
||||
@Override
|
||||
public String serialize(T from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(String serialized, Class<T> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return Enum.valueOf(wanted, serialized.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalPropertyValueException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the difficulty-property.
|
||||
*/
|
||||
private static final class DifficultyPropertySerializor implements Serializor<Difficulty, String> {
|
||||
@Override
|
||||
public String serialize(Difficulty from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Difficulty deserialize(String serialized, Class<Difficulty> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return Difficulty.getByValue(Integer.parseInt(serialized));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
return Difficulty.valueOf(serialized.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new IllegalPropertyValueException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the gameMode-property.
|
||||
*/
|
||||
private static final class GameModePropertySerializor implements Serializor<GameMode, String> {
|
||||
@Override
|
||||
public String serialize(GameMode from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode deserialize(String serialized, Class<GameMode> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return GameMode.getByValue(Integer.parseInt(serialized));
|
||||
} catch (NumberFormatException nfe) {
|
||||
}
|
||||
try {
|
||||
return GameMode.valueOf(serialized.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new IllegalPropertyValueException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the time-property.
|
||||
*/
|
||||
private static final class TimePropertySerializor implements Serializor<Long, String> {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
private static final String TIME_REGEX = "(\\d\\d?):?(\\d\\d)(a|p)?m?";
|
||||
private static final Map<String, String> TIME_ALIASES;
|
||||
static {
|
||||
Map<String, String> staticTimes = new HashMap<String, String>();
|
||||
staticTimes.put("morning", "8:00");
|
||||
staticTimes.put("day", "12:00");
|
||||
staticTimes.put("noon", "12:00");
|
||||
staticTimes.put("midnight", "0:00");
|
||||
staticTimes.put("night", "20:00");
|
||||
|
||||
// now set TIME_ALIASES to a "frozen" map
|
||||
TIME_ALIASES = Collections.unmodifiableMap(staticTimes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(Long from) {
|
||||
// I'm tired, so they get time in 24 hour for now.
|
||||
// Someone else can add 12 hr format if they want :P
|
||||
|
||||
int hours = (int) ((from / 1000 + 8) % 24);
|
||||
int minutes = (int) (60 * (from % 1000) / 1000);
|
||||
|
||||
return String.format("%d:%02d", hours, minutes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long deserialize(String serialized, Class<Long> wanted) throws IllegalPropertyValueException {
|
||||
if (TIME_ALIASES.containsKey(serialized.toLowerCase())) {
|
||||
serialized = TIME_ALIASES.get(serialized.toLowerCase());
|
||||
}
|
||||
// Regex that extracts a time in the following formats:
|
||||
// 11:11pm, 11:11, 23:11, 1111, 1111p, and the aliases at the top of this file.
|
||||
Pattern pattern = Pattern.compile(TIME_REGEX, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(serialized);
|
||||
matcher.find();
|
||||
int hour = 0;
|
||||
double minute = 0;
|
||||
int count = matcher.groupCount();
|
||||
if (count >= 2) {
|
||||
hour = Integer.parseInt(matcher.group(1));
|
||||
minute = Integer.parseInt(matcher.group(2));
|
||||
}
|
||||
// If there were 4 matches (all, hour, min, am/pm)
|
||||
if (count == 4) {
|
||||
// We want 24 hour time for calcs, but if they
|
||||
// added a p[m], turn it into a 24 hr one.
|
||||
if (matcher.group(3).equals("p")) {
|
||||
hour += 12;
|
||||
}
|
||||
}
|
||||
// Translate 24th hour to 0th hour.
|
||||
if (hour == 24) {
|
||||
hour = 0;
|
||||
}
|
||||
// Clamp the hour
|
||||
if (hour > 23 || hour < 0) {
|
||||
throw new IllegalPropertyValueException("Illegal hour!");
|
||||
}
|
||||
// Clamp the minute
|
||||
if (minute > 59 || minute < 0) {
|
||||
throw new IllegalPropertyValueException("Illegal minute!");
|
||||
}
|
||||
// 60 seconds in a minute, time needs to be in hrs * 1000, per
|
||||
// the bukkit docs.
|
||||
double totaltime = (hour + (minute / 60.0)) * 1000;
|
||||
// Somehow there's an 8 hour offset...
|
||||
totaltime -= 8000;
|
||||
if (totaltime < 0) {
|
||||
totaltime = 24000 + totaltime;
|
||||
}
|
||||
|
||||
return (long) totaltime;
|
||||
}
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Begin properties
|
||||
@Property(description = "Sorry, 'hidden' must either be: true or false.")
|
||||
private volatile boolean hidden;
|
||||
@Property(description = "Alias must be a valid string.")
|
||||
private volatile String alias;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
|
||||
private volatile EnglishChatColor color;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'style' must be a valid style-name.")
|
||||
private volatile EnglishChatStyle style;
|
||||
@Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
|
||||
volatile VirtualProperty<Boolean> pvp; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Scale must be a positive double value. ex: 2.3")
|
||||
private volatile double scale;
|
||||
@Property(description = "You must set this to the NAME not alias of a world.")
|
||||
private volatile String respawnWorld;
|
||||
@Property(description = "Sorry, this must either be: true or false.")
|
||||
private volatile boolean allowWeather;
|
||||
@Property(serializor = DifficultyPropertySerializor.class, virtualType = Difficulty.class, persistVirtual = true,
|
||||
description = "Difficulty must be set as one of the following: peaceful easy normal hard")
|
||||
volatile VirtualProperty<Difficulty> difficulty; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Sorry, 'animals' must either be: true or false.")
|
||||
private volatile SpawnSettings spawning;
|
||||
@Property
|
||||
private volatile EntryFee entryfee;
|
||||
@Property(description = "Sorry, 'hunger' must either be: true or false.")
|
||||
private volatile boolean hunger;
|
||||
@Property(description = "Sorry, 'autoheal' must either be: true or false.")
|
||||
private volatile boolean autoHeal;
|
||||
@Property(description = "Sorry, 'adjustspawn' must either be: true or false.")
|
||||
private volatile boolean adjustSpawn;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Allow portal forming must be NONE, ALL, NETHER or END.")
|
||||
private volatile AllowedPortalType portalForm;
|
||||
@Property(serializor = GameModePropertySerializor.class, description = "GameMode must be set as one of the following: survival creative")
|
||||
private volatile GameMode gameMode;
|
||||
@Property(description = "Sorry, this must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
|
||||
volatile VirtualProperty<Boolean> keepSpawnInMemory; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile SpawnLocation spawnLocation; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(virtualType = Location.class,
|
||||
description = "There is no help available for this variable. Go bug Rigby90 about it.")
|
||||
volatile VirtualProperty<Location> spawn; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Set this to false ONLY if you don't want this world to load itself on server restart.")
|
||||
private volatile boolean autoLoad;
|
||||
@Property(description = "If a player dies in this world, shoudld they go to their bed?")
|
||||
private volatile boolean bedRespawn;
|
||||
@Property
|
||||
private volatile List<String> worldBlacklist;
|
||||
@Property(serializor = TimePropertySerializor.class, virtualType = Long.class,
|
||||
description = "Set the time to whatever you want! (Will NOT freeze time)")
|
||||
volatile VirtualProperty<Long> time; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile Environment environment; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile long seed; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
private volatile String generator;
|
||||
@Property
|
||||
private volatile int playerLimit;
|
||||
@Property
|
||||
private volatile boolean allowFlight;
|
||||
// End of properties
|
||||
// --------------------------------------------------------------
|
||||
|
||||
void setValidator(String fieldName, Validator validator) {
|
||||
registerValidator(fieldName, validator); //To change body of overridden methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void copyValues(SerializationConfig other) {
|
||||
super.copyValues(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* This prepares the MVWorld for unloading.
|
||||
*/
|
||||
public void cacheVirtualProperties() {
|
||||
try {
|
||||
this.buildVPropChanges();
|
||||
} catch (IllegalStateException e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void setDefaults() {
|
||||
this.hidden = false;
|
||||
this.alias = new String();
|
||||
this.color = EnglishChatColor.WHITE;
|
||||
this.style = EnglishChatStyle.NORMAL;
|
||||
this.scale = 1D;
|
||||
this.respawnWorld = new String();
|
||||
this.allowWeather = true;
|
||||
this.spawning = new SpawnSettings();
|
||||
this.entryfee = new EntryFee();
|
||||
this.hunger = true;
|
||||
this.autoHeal = true;
|
||||
this.adjustSpawn = true;
|
||||
this.portalForm = AllowedPortalType.ALL;
|
||||
this.gameMode = GameMode.SURVIVAL;
|
||||
this.spawnLocation = new NullLocation();
|
||||
this.autoLoad = true;
|
||||
this.bedRespawn = true;
|
||||
this.worldBlacklist = new ArrayList<String>();
|
||||
this.generator = null;
|
||||
this.playerLimit = -1;
|
||||
this.allowFlight = true;
|
||||
}
|
||||
|
||||
private static double getDefaultScale(Environment environment) {
|
||||
if (environment == Environment.NETHER) {
|
||||
return 8.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
} else if (environment == Environment.THE_END) {
|
||||
return 16.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* getAliases().
|
||||
* @return The alias-map.
|
||||
* @see SerializationConfig
|
||||
*/
|
||||
protected static Map<String, String> getAliases() {
|
||||
return PROPERTY_ALIASES;
|
||||
}
|
||||
|
||||
void flushChanges() {
|
||||
this.flushPendingVPropChanges();
|
||||
}
|
||||
|
||||
String getAlias() {
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.setPropertyValueUnchecked("alias", alias);
|
||||
}
|
||||
|
||||
public Environment getEnvironment() {
|
||||
return this.environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.setPropertyValueUnchecked("environment", environment);
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
public void setSeed(long seed) {
|
||||
this.setPropertyValueUnchecked("seed", seed);
|
||||
}
|
||||
|
||||
public String getGenerator() {
|
||||
return this.generator;
|
||||
}
|
||||
|
||||
public void setGenerator(String generator) {
|
||||
this.setPropertyValueUnchecked("generator", generator);
|
||||
}
|
||||
|
||||
public int getPlayerLimit() {
|
||||
return this.playerLimit;
|
||||
}
|
||||
|
||||
public void setPlayerLimit(int limit) {
|
||||
this.setPropertyValueUnchecked("playerLimit", limit);
|
||||
}
|
||||
|
||||
public boolean canAnimalsSpawn() {
|
||||
return this.spawning.getAnimalSettings().doSpawn();
|
||||
}
|
||||
|
||||
public void setAllowAnimalSpawn(boolean animals) {
|
||||
this.setPropertyValueUnchecked("spawning.animals.spawn", animals);
|
||||
}
|
||||
|
||||
public List<String> getAnimalList() {
|
||||
// These don't fire events at the moment. Should they?
|
||||
return this.spawning.getAnimalSettings().getExceptions();
|
||||
}
|
||||
|
||||
public boolean canMonstersSpawn() {
|
||||
return this.spawning.getMonsterSettings().doSpawn();
|
||||
}
|
||||
|
||||
public void setAllowMonsterSpawn(boolean monsters) {
|
||||
this.setPropertyValueUnchecked("spawning.monsters.spawn", monsters);
|
||||
}
|
||||
|
||||
public int getAnimalSpawnRate() {
|
||||
return this.spawning.getAnimalSettings().getSpawnRate();
|
||||
}
|
||||
|
||||
public int getMonsterSpawnRate() {
|
||||
return this.spawning.getMonsterSettings().getSpawnRate();
|
||||
}
|
||||
|
||||
public List<String> getMonsterList() {
|
||||
// These don't fire events at the moment. Should they?
|
||||
return this.spawning.getMonsterSettings().getExceptions();
|
||||
}
|
||||
|
||||
public boolean isPVPEnabled() {
|
||||
return this.pvp.get();
|
||||
}
|
||||
|
||||
public void setPVPMode(boolean pvp) {
|
||||
this.setPropertyValueUnchecked("pvp", pvp);
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.setPropertyValueUnchecked("hidden", hidden);
|
||||
}
|
||||
|
||||
public List<String> getWorldBlacklist() {
|
||||
return this.worldBlacklist;
|
||||
}
|
||||
|
||||
public double getScaling() {
|
||||
return this.scale;
|
||||
}
|
||||
|
||||
public boolean setScaling(double scaling) {
|
||||
return this.setPropertyValueUnchecked("scale", scaling);
|
||||
}
|
||||
|
||||
public boolean setColor(String aliasColor) {
|
||||
return this.setPropertyUnchecked("color", aliasColor);
|
||||
}
|
||||
|
||||
public boolean setColor(EnglishChatColor color) {
|
||||
return this.setPropertyValueUnchecked("color", color);
|
||||
}
|
||||
|
||||
public EnglishChatColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public String getRespawnToWorld() {
|
||||
return this.respawnWorld;
|
||||
}
|
||||
|
||||
public boolean setRespawnToWorld(String respawnToWorld) {
|
||||
return this.setPropertyValueUnchecked("respawnWorld", respawnToWorld);
|
||||
}
|
||||
|
||||
public int getCurrency() {
|
||||
return this.entryfee.getCurrency();
|
||||
}
|
||||
|
||||
public void setCurrency(int currency) {
|
||||
this.setPropertyValueUnchecked("entryfee.currency", currency);
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return this.entryfee.getAmount();
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.setPropertyValueUnchecked("entryfee.amount", price);
|
||||
}
|
||||
|
||||
public boolean setGameMode(String mode) {
|
||||
return this.setPropertyUnchecked("gameMode", mode);
|
||||
}
|
||||
|
||||
public boolean setGameMode(GameMode mode) {
|
||||
return this.setPropertyValueUnchecked("gameMode", mode);
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
public void setEnableWeather(boolean weather) {
|
||||
this.setPropertyValueUnchecked("allowWeather", weather);
|
||||
}
|
||||
|
||||
public boolean isWeatherEnabled() {
|
||||
return this.allowWeather;
|
||||
}
|
||||
|
||||
public boolean isKeepingSpawnInMemory() {
|
||||
return this.keepSpawnInMemory.get();
|
||||
}
|
||||
|
||||
public void setKeepSpawnInMemory(boolean value) {
|
||||
this.setPropertyValueUnchecked("keepSpawnInMemory", value);
|
||||
}
|
||||
|
||||
public boolean getHunger() {
|
||||
return this.hunger;
|
||||
}
|
||||
|
||||
public void setHunger(boolean hunger) {
|
||||
this.setPropertyValueUnchecked("hunger", hunger);
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
return this.spawn.get();
|
||||
}
|
||||
|
||||
public void setSpawnLocation(Location l) {
|
||||
this.setPropertyValueUnchecked("spawn", l);
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return this.difficulty.get();
|
||||
}
|
||||
|
||||
@Deprecated // SUPPRESS CHECKSTYLE: Deprecated
|
||||
public boolean setDifficulty(String difficulty) {
|
||||
return this.setPropertyUnchecked("difficulty", difficulty);
|
||||
}
|
||||
|
||||
public boolean setDifficulty(Difficulty difficulty) {
|
||||
return this.setPropertyValueUnchecked("difficulty", difficulty);
|
||||
}
|
||||
|
||||
public boolean getAutoHeal() {
|
||||
return this.autoHeal;
|
||||
}
|
||||
|
||||
public void setAutoHeal(boolean heal) {
|
||||
this.setPropertyValueUnchecked("autoHeal", heal);
|
||||
}
|
||||
|
||||
public void setAdjustSpawn(boolean adjust) {
|
||||
this.setPropertyValueUnchecked("adjustSpawn", adjust);
|
||||
}
|
||||
|
||||
public boolean getAdjustSpawn() {
|
||||
return this.adjustSpawn;
|
||||
}
|
||||
|
||||
public void setAutoLoad(boolean load) {
|
||||
this.setPropertyValueUnchecked("autoLoad", load);
|
||||
}
|
||||
|
||||
public boolean getAutoLoad() {
|
||||
return this.autoLoad;
|
||||
}
|
||||
|
||||
public void setBedRespawn(boolean respawn) {
|
||||
this.setPropertyValueUnchecked("bedRespawn", respawn);
|
||||
}
|
||||
|
||||
public boolean getBedRespawn() {
|
||||
return this.bedRespawn;
|
||||
}
|
||||
|
||||
public String getAllPropertyNames() {
|
||||
ChatColor myColor = ChatColor.AQUA;
|
||||
StringBuilder result = new StringBuilder();
|
||||
Map<String, Object> serialized = this.serialize();
|
||||
for (String key : serialized.keySet()) {
|
||||
result.append(myColor).append(key).append(' ');
|
||||
myColor = (myColor == ChatColor.AQUA) ? ChatColor.GOLD : ChatColor.AQUA;
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return this.getPropertyUnchecked("time");
|
||||
}
|
||||
|
||||
public boolean setTime(String timeAsString) {
|
||||
return this.setPropertyUnchecked("time", timeAsString);
|
||||
}
|
||||
|
||||
public AllowedPortalType getAllowedPortals() {
|
||||
return portalForm;
|
||||
}
|
||||
|
||||
public void allowPortalMaking(AllowedPortalType portalType) {
|
||||
this.setPropertyValueUnchecked("portalForm", portalType);
|
||||
}
|
||||
|
||||
public EnglishChatStyle getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
public boolean setStyle(String style) {
|
||||
return this.setPropertyUnchecked("style", style);
|
||||
}
|
||||
|
||||
public boolean getAllowFlight() {
|
||||
return this.allowFlight;
|
||||
}
|
||||
|
||||
public void setAllowFlight(final boolean allowFlight) {
|
||||
this.setPropertyValueUnchecked("allowFlight", allowFlight);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.fernferret.allpay.AllPay;
|
||||
import com.fernferret.allpay.commons.GenericBank;
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
@@ -18,7 +18,9 @@ import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
@@ -28,6 +30,15 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public interface Core {
|
||||
|
||||
/**
|
||||
* Gets the Multiverse config file.
|
||||
*
|
||||
* @return The Multiverse config file.
|
||||
* @deprecated Don't modify the config-file manually!
|
||||
*/
|
||||
@Deprecated
|
||||
FileConfiguration getMVConfiguration();
|
||||
|
||||
/**
|
||||
* Gets the Banking system that Multiverse-Core has hooked into.
|
||||
*
|
||||
|
||||
@@ -30,14 +30,14 @@ public interface MVPlugin extends LoggablePlugin {
|
||||
/**
|
||||
* Gets the reference to MultiverseCore.
|
||||
*
|
||||
* @return A valid {@link com.onarandombox.MultiverseCore}.
|
||||
* @return A valid {@link MultiverseCore}.
|
||||
*/
|
||||
MultiverseCore getCore();
|
||||
|
||||
/**
|
||||
* Sets the reference to MultiverseCore.
|
||||
*
|
||||
* @param core A valid {@link com.onarandombox.MultiverseCore}.
|
||||
* @param core A valid {@link MultiverseCore}.
|
||||
*/
|
||||
void setCore(MultiverseCore core);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
|
||||
/**
|
||||
@@ -146,6 +148,18 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
||||
*/
|
||||
boolean getUseAsyncChat();
|
||||
|
||||
/**
|
||||
* Sets the locale.
|
||||
* @param locale The new value.
|
||||
*/
|
||||
void setLocale(Locale locale);
|
||||
|
||||
/**
|
||||
* Gets the locale.
|
||||
* @return locale
|
||||
*/
|
||||
Locale getLocale();
|
||||
|
||||
/**
|
||||
* Sets whether to suppress startup messages.
|
||||
*
|
||||
@@ -159,32 +173,4 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
||||
* @return true if we are suppressing startup messages.
|
||||
*/
|
||||
boolean getSilentStart();
|
||||
|
||||
/**
|
||||
* Sets whether or not to let Bukkit determine portal search radius on its own or if Multiverse should give input.
|
||||
*
|
||||
* @param useDefaultPortalSearch True to let Bukkit determine portal search radius on its own.
|
||||
*/
|
||||
void setUseDefaultPortalSearch(boolean useDefaultPortalSearch);
|
||||
|
||||
/**
|
||||
* Gets whether or not Bukkit will be determining portal search radius on its own or if Multiverse should help.
|
||||
*
|
||||
* @return True means Bukkit will use its own default values.
|
||||
*/
|
||||
boolean isUsingDefaultPortalSearch();
|
||||
|
||||
/**
|
||||
* Sets the radius at which vanilla style portals will be searched for to connect to worlds together.
|
||||
*
|
||||
* @param searchRadius The portal search radius.
|
||||
*/
|
||||
void setPortalSearchRadius(int searchRadius);
|
||||
|
||||
/**
|
||||
* Gets the radius at which vanilla style portals will be searched for to connect to worlds together.
|
||||
*
|
||||
* @return The portal search radius.
|
||||
*/
|
||||
int getPortalSearchRadius();
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import java.util.Collection;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
|
||||
/**
|
||||
* Multiverse-messaging.
|
||||
*/
|
||||
@@ -14,6 +16,27 @@ public interface MultiverseMessaging {
|
||||
*/
|
||||
void setCooldown(int milliseconds);
|
||||
|
||||
/**
|
||||
* Sends a message to the specified sender if the cooldown has passed.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param message The message to send.
|
||||
* @param formatArgs Format arguments for the message.
|
||||
* @return true if the message was sent, false if not.
|
||||
*/
|
||||
boolean sendMessage(CommandSender sender, MultiverseMessage message, Object...formatArgs);
|
||||
|
||||
/**
|
||||
* Sends a message to the specified sender if the cooldown has passed.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param message The message to send.
|
||||
* @param ignoreCooldown If true this message will always be sent. Useful for things like menus
|
||||
* @param formatArgs Format arguments for the message.
|
||||
* @return true if the message was sent, false if not.
|
||||
*/
|
||||
boolean sendMessage(CommandSender sender, MultiverseMessage message, boolean ignoreCooldown, Object... formatArgs);
|
||||
|
||||
/**
|
||||
* Sends a message to the specified sender if the cooldown has passed.
|
||||
*
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
import com.onarandombox.MultiverseCore.utils.DebugLog;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
|
||||
@@ -105,7 +106,7 @@ public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!this.isEnabled()) {
|
||||
sender.sendMessage("This plugin is Disabled!");
|
||||
this.core.getMessaging().sendMessage(sender, MultiverseMessage.CH_PLUGIN_DISABLED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -619,11 +620,11 @@ public interface MultiverseWorld {
|
||||
* @param autoLoad True if players dying in this world respawn at their bed.
|
||||
*/
|
||||
void setBedRespawn(boolean autoLoad);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the player limit for this world after which players without an override
|
||||
* permission node will not be allowed in. A value of -1 or less signifies no limit
|
||||
*
|
||||
*
|
||||
* @param limit The new limit
|
||||
*/
|
||||
void setPlayerLimit(int limit);
|
||||
@@ -631,7 +632,7 @@ public interface MultiverseWorld {
|
||||
/**
|
||||
* Gets the player limit for this world after which players without an override
|
||||
* permission node will not be allowed in. A value of -1 or less signifies no limit
|
||||
*
|
||||
*
|
||||
* @return The player limit
|
||||
*/
|
||||
int getPlayerLimit();
|
||||
@@ -684,18 +685,4 @@ public interface MultiverseWorld {
|
||||
* @return All property names, with alternating colors.
|
||||
*/
|
||||
String getAllPropertyNames();
|
||||
|
||||
/**
|
||||
* Whether or not players are allowed to fly in this world.
|
||||
*
|
||||
* @return True if players allowed to fly in this world.
|
||||
*/
|
||||
boolean getAllowFlight();
|
||||
|
||||
/**
|
||||
* Sets whether or not players are allowed to fly in this world.
|
||||
*
|
||||
* @param allowFlight True to allow flight in this world.
|
||||
*/
|
||||
void setAllowFlight(final boolean allowFlight);
|
||||
}
|
||||
@@ -8,6 +8,8 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -55,11 +57,11 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
|
||||
|
||||
private void showList(CommandSender sender, List<String> args) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.list", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to list anchors!");
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.CMD_ANCHOR_NOLISTPERM);
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]====");
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.CMD_ANCHOR_LISTHEADER);
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
@@ -72,13 +74,12 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
|
||||
if (filterObject.getFilter().length() > 0) {
|
||||
availableAnchors = this.getFilteredItems(availableAnchors, filterObject.getFilter());
|
||||
if (availableAnchors.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
|
||||
+ "No anchors matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.CMD_ANCHOR_NOMATCH, filterObject.getFilter());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (availableAnchors.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No anchors were defined.");
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.CMD_ANCHOR_NODEF);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +100,7 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
|
||||
filterObject.setPage(1);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages);
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.CMD_ANCHOR_PAGEHEADER, filterObject.getPage(), totalPages);
|
||||
|
||||
this.showPage(filterObject.getPage(), sender, availableAnchors);
|
||||
}
|
||||
@@ -115,33 +116,24 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
|
||||
return;
|
||||
}
|
||||
if (args.size() == 2 && args.get(1).equalsIgnoreCase("-d")) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.delete", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to delete anchors!");
|
||||
} else {
|
||||
if (this.plugin.getAnchorManager().deleteAnchor(args.get(0))) {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.RED + "deleted!");
|
||||
} else {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "deleted!");
|
||||
}
|
||||
}
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.delete", true))
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.CMD_ANCHOR_NODELPERM);
|
||||
else
|
||||
this.plugin.getMessaging().sendMessage(sender, this.plugin.getAnchorManager().deleteAnchor(args.get(0))
|
||||
? MultiverseMessage.CMD_ANCHOR_DELSUCCESS : MultiverseMessage.CMD_ANCHOR_DELFAIL, args.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to create Anchors.");
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.CMD_ANCHOR_CONSOLECREATE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.create", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to create anchors!");
|
||||
} else {
|
||||
Player player = (Player) sender;
|
||||
if (this.plugin.getAnchorManager().saveAnchorLocation(args.get(0), player.getLocation())) {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.GREEN + "created!");
|
||||
} else {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "created!");
|
||||
}
|
||||
}
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.create", true))
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.CMD_ANCHOR_NOCREATEPERM);
|
||||
else
|
||||
this.plugin.getMessaging().sendMessage(sender, this.plugin.getAnchorManager().saveAnchorLocation(args.get(0), ((Player) sender).getLocation())
|
||||
? MultiverseMessage.CMD_ANCHOR_CREATESUCCESS : MultiverseMessage.CMD_ANCHOR_CREATEFAIL, args.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -39,15 +40,12 @@ public class CheckCommand extends MultiverseCommand {
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = this.plugin.getServer().getPlayer(args.get(0));
|
||||
if (p == null) {
|
||||
sender.sendMessage("Could not find player " + ChatColor.GREEN + args.get(0));
|
||||
sender.sendMessage("Are they online?");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CHECK_NOSUCHPLAYER, args.get(0));
|
||||
return;
|
||||
}
|
||||
MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1));
|
||||
if (dest instanceof InvalidDestination) {
|
||||
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?");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CHECK_NOSUCHDEST);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -50,8 +51,7 @@ public class CloneCommand extends MultiverseCommand {
|
||||
objectArgs.add(CommandHandler.getFlag("-g", args));
|
||||
if (!this.worldManager.isMVWorld(args.get(0))) {
|
||||
// If no world was found, we can't clone.
|
||||
sender.sendMessage("Sorry, Multiverse doesn't know about world " + args.get(0) + ", so we can't clone it!");
|
||||
sender.sendMessage("Check the " + ChatColor.GREEN + "/mv list" + ChatColor.WHITE + " command to verify it is listed.");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CLONE_NOSUCHWORLD, args.get(0));
|
||||
return;
|
||||
}
|
||||
this.plugin.getCommandHandler().queueCommand(sender, "mvclone", "cloneWorld", objectArgs,
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
@@ -52,7 +54,7 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
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)));
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CONFIG_SETFAIL, args.get(0), args.get(1));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,10 +65,10 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
if (this.plugin.saveMVConfigs()) {
|
||||
sender.sendMessage(ChatColor.GREEN + "SUCCESS!" + ChatColor.WHITE + " Values were updated successfully!");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CLONE_SUCCESS);
|
||||
this.plugin.loadConfigs();
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "FAIL!" + ChatColor.WHITE + " Check your console for details!");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CONFIG_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
@@ -68,20 +69,18 @@ public class CreateCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD + ChatColor.UNDERLINE
|
||||
+ "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName);
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CREATE_WORLDEXISTS, worldName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldFile.exists()) {
|
||||
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
|
||||
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CREATE_FILEEXISTS);
|
||||
return;
|
||||
}
|
||||
|
||||
Environment environment = EnvironmentCommand.getEnvFromString(env);
|
||||
if (environment == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CREATE_INVALIDENV);
|
||||
EnvironmentCommand.showEnvironments(sender);
|
||||
return;
|
||||
}
|
||||
@@ -92,7 +91,7 @@ public class CreateCommand extends MultiverseCommand {
|
||||
}
|
||||
WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString);
|
||||
if (type == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid World Type.");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CREATE_INVALIDTYPE);
|
||||
EnvironmentCommand.showWorldTypes(sender);
|
||||
return;
|
||||
}
|
||||
@@ -105,16 +104,16 @@ public class CreateCommand extends MultiverseCommand {
|
||||
}
|
||||
if (this.worldManager.getChunkGenerator(genarray.get(0), genarray.get(1), "test") == null) {
|
||||
// We have an invalid generator.
|
||||
sender.sendMessage("Invalid generator! '" + generator + "'. " + ChatColor.RED + "Aborting world creation.");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_CREATE_INVALIDGEN, generator);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'...");
|
||||
Command.broadcastCommandMessage(sender, this.plugin.getMessageProvider().getMessage(MultiverseMessage.CMD_CREATE_START, worldName));
|
||||
|
||||
if (this.worldManager.addWorld(worldName, environment, seed, type, allowStructures, generator, useSpawnAdjust)) {
|
||||
Command.broadcastCommandMessage(sender, "Complete!");
|
||||
Command.broadcastCommandMessage(sender, this.plugin.getMessageProvider().getMessage(MultiverseMessage.CMD_CREATE_COMPLETE));
|
||||
} else {
|
||||
Command.broadcastCommandMessage(sender, "FAILED.");
|
||||
Command.broadcastCommandMessage(sender, this.plugin.getMessageProvider().getMessage(MultiverseMessage.CMD_CREATE_FAILED));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +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.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class GameruleCommand extends MultiverseCommand {
|
||||
|
||||
public GameruleCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Set a Minecraft Game Rule for a World.");
|
||||
this.setCommandUsage("/mv gamerule " + ChatColor.GREEN + "{RULE} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mv gamerule");
|
||||
this.addKey("mv rule");
|
||||
this.addKey("mvgamerule");
|
||||
this.addKey("mvrule");
|
||||
this.addCommandExample("/mv gamerule " + ChatColor.GREEN + "doMobLoot false");
|
||||
this.addCommandExample("/mvrule " + ChatColor.GREEN + "keepInventory true " + ChatColor.RED + "world_nether");
|
||||
this.setPermission("multiverse.core.gamerule.set", "Allows a player to set a gamerule.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
final Player p;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
} else {
|
||||
p = null;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final String gameRule = args.get(0);
|
||||
final String value = args.get(1);
|
||||
final World world;
|
||||
if (args.size() == 2) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorld(args.get(2));
|
||||
}
|
||||
|
||||
if (world.setGameRuleValue(gameRule, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||
+ ChatColor.WHITE + " cannot be set to " + ChatColor.RED + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class GamerulesCommand extends MultiverseCommand {
|
||||
|
||||
public GamerulesCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("List the Minecraft Game Rules for a World.");
|
||||
this.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv gamerules");
|
||||
this.addKey("mv rules");
|
||||
this.addKey("mvgamerules");
|
||||
this.addKey("mvrules");
|
||||
this.addCommandExample("/mv gamerules");
|
||||
this.addCommandExample("/mvrules " + ChatColor.RED + "world_nether");
|
||||
this.setPermission("multiverse.core.gamerule.list", "Allows a player to list gamerules.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
final Player p;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
} else {
|
||||
p = null;
|
||||
}
|
||||
|
||||
if (args.size() == 0 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final World world;
|
||||
if (args.size() == 0) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorld(args.get(0));
|
||||
}
|
||||
|
||||
final StringBuilder gameRules = new StringBuilder();
|
||||
for (final String gameRule : world.getGameRules()) {
|
||||
if (gameRules.length() != 0) {
|
||||
gameRules.append(ChatColor.WHITE).append(", ");
|
||||
}
|
||||
gameRules.append(ChatColor.AQUA).append(gameRule).append(ChatColor.WHITE).append(": ");
|
||||
gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(gameRule));
|
||||
}
|
||||
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
|
||||
sender.sendMessage(gameRules.toString());
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
@@ -24,7 +26,7 @@ public class GeneratorCommand extends MultiverseCommand {
|
||||
|
||||
public GeneratorCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Information");
|
||||
this.setName("Generator Information");
|
||||
this.setCommandUsage("/mv generators");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mv generators");
|
||||
@@ -45,16 +47,16 @@ public class GeneratorCommand extends MultiverseCommand {
|
||||
generators.add(p.getDescription().getName());
|
||||
}
|
||||
}
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Loaded Generator Plugins ---");
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_GENERATOR_LISTHEADER);
|
||||
String loadedGens = "";
|
||||
boolean altColor = false;
|
||||
for (String s : generators) {
|
||||
loadedGens += (altColor ? ChatColor.YELLOW : ChatColor.WHITE) + s + " ";
|
||||
altColor = !altColor;
|
||||
}
|
||||
if (loadedGens.length() == 0) {
|
||||
loadedGens = ChatColor.RED + "No Generator Plugins found.";
|
||||
}
|
||||
sender.sendMessage(loadedGens);
|
||||
if (loadedGens.length() == 0)
|
||||
this.messaging.sendMessage(sender, MultiverseMessage.CMD_GENERATOR_NOGENSFOUND);
|
||||
else
|
||||
this.messaging.sendMessage(sender, loadedGens, false);
|
||||
}
|
||||
}
|
||||
@@ -122,8 +122,7 @@ public class InfoCommand extends MultiverseCommand {
|
||||
//message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors));
|
||||
Location spawn = world.getSpawnLocation();
|
||||
message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors));
|
||||
message.add(new FancyMessage("World Scale: ", String.valueOf(world.getScaling()), colors));
|
||||
message.add(new FancyMessage("World Seed: ", String.valueOf(world.getSeed()), colors));
|
||||
message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors));
|
||||
if (world.getPrice() > 0) {
|
||||
final String formattedAmount;
|
||||
if (world.getCurrency() <= 0 && plugin.getVaultHandler().getEconomy() != null) {
|
||||
|
||||
@@ -9,6 +9,8 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.localization.MessageProvider;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -22,16 +24,18 @@ import java.util.List;
|
||||
* Displays a listing of all worlds that a player can enter.
|
||||
*/
|
||||
public class ListCommand extends PaginatedCoreCommand<String> {
|
||||
private MessageProvider provider;
|
||||
|
||||
public ListCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Listing");
|
||||
provider = plugin.getMessageProvider();
|
||||
this.setName(provider.getMessage(MultiverseMessage.CMD_LIST_NAME));
|
||||
this.setCommandUsage("/mv list");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mvlist");
|
||||
this.addKey("mvl");
|
||||
this.addKey("mv list");
|
||||
this.setPermission("multiverse.core.list.worlds", "Displays a listing of all worlds that you can enter.", PermissionDefault.OP);
|
||||
this.setPermission("multiverse.core.list.worlds", provider.getMessage(MultiverseMessage.CMD_LIST_DESC), PermissionDefault.OP);
|
||||
this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
|
||||
@@ -66,7 +70,7 @@ public class ListCommand extends PaginatedCoreCommand<String> {
|
||||
}
|
||||
for (String name : this.plugin.getMVWorldManager().getUnloadedWorlds()) {
|
||||
if (p == null || this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + name, true)) {
|
||||
worldList.add(ChatColor.GRAY + name + " - UNLOADED");
|
||||
worldList.add(ChatColor.GRAY + name + " - " + "UNLOADED");
|
||||
}
|
||||
}
|
||||
return worldList;
|
||||
@@ -91,7 +95,7 @@ public class ListCommand extends PaginatedCoreCommand<String> {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse World List ]====");
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ " + this.provider.getMessage(MultiverseMessage.CMD_LIST_TITLE) + " ]====");
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
@@ -104,8 +108,7 @@ public class ListCommand extends PaginatedCoreCommand<String> {
|
||||
if (filterObject.getFilter().length() > 0) {
|
||||
availableWorlds = this.getFilteredItems(availableWorlds, filterObject.getFilter());
|
||||
if (availableWorlds.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
|
||||
+ "No worlds matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + provider.getMessage(MultiverseMessage.CMD_LIST_NO_MATCH) + " " + ChatColor.AQUA + filterObject.getFilter());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,6 @@ public class SetSpawnCommand extends MultiverseCommand {
|
||||
foundWorld.setAdjustSpawn(false);
|
||||
}
|
||||
sender.sendMessage("Spawn was set to: " + plugin.getLocationManipulation().strCoords(p.getLocation()));
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully (Pitch/Yaws).");
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
||||
import me.main__.util.SerializationConfig.Serializor;
|
||||
|
||||
public class LocaleSerializor implements Serializor<Locale, String> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Locale deserialize(String arg0, Class<Locale> arg1) throws IllegalPropertyValueException {
|
||||
return new Locale(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String serialize(Locale arg0) {
|
||||
return arg0.getLanguage();
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.MapInitializeEvent;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
/**
|
||||
* A listener for bukkit map events.
|
||||
*/
|
||||
public class MVMapListener implements Listener {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
public MVMapListener(final MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a map is initialized.
|
||||
* @param event The event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void mapInitialize(final MapInitializeEvent event) {
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
if ((player.getItemInHand().getType() == Material.MAP
|
||||
|| player.getItemInHand().getType() == Material.EMPTY_MAP)
|
||||
&& player.getItemInHand().getDurability() == event.getMap().getId()) {
|
||||
final Location playerLoc = player.getLocation();
|
||||
final MapView map = event.getMap();
|
||||
map.setCenterX(playerLoc.getBlockX());
|
||||
map.setCenterZ(playerLoc.getBlockZ());
|
||||
map.setWorld(playerLoc.getWorld());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
import com.onarandombox.MultiverseCore.utils.PermissionTools;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -121,12 +121,12 @@ public class MVPlayerListener implements Listener {
|
||||
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.plugin.getMessaging().sendMessage(p, MultiverseMessage.LISTENER_PLAYER_LOSTACCESSPERM);
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
}
|
||||
}
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
playerWorld.put(p.getName(), p.getWorld().getName());
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class MVPlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void playerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
// Permissions now determine whether or not to handle a gamemode.
|
||||
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName());
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public class MVPlayerListener implements Listener {
|
||||
+ "' don't have the FUNDS required to enter it.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Check if player is allowed to enter the world if we're enforcing permissions
|
||||
if (plugin.getMVConfig().getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
|
||||
@@ -209,7 +209,7 @@ public class MVPlayerListener implements Listener {
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
+ "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off.");
|
||||
}
|
||||
|
||||
|
||||
// Does a limit actually exist?
|
||||
if (toWorld.getPlayerLimit() > -1) {
|
||||
// Are there equal or more people on the world than the limit?
|
||||
@@ -225,7 +225,7 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// By this point anything cancelling the event has returned on the method, meaning the teleport is a success \o/
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
}
|
||||
@@ -300,9 +300,6 @@ public class MVPlayerListener implements Listener {
|
||||
+ "' was allowed to go to '" + event.getTo().getWorld().getName()
|
||||
+ "' because enforceaccess is off.");
|
||||
}
|
||||
if (!plugin.getMVConfig().isUsingDefaultPortalSearch() && event.getPortalTravelAgent() != null) {
|
||||
event.getPortalTravelAgent().setSearchRadius(plugin.getMVConfig().getPortalSearchRadius());
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPlayerToDefaultWorld(final Player player) {
|
||||
@@ -317,13 +314,13 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
// FOLLOWING 2 Methods and Private class handle Per Player GameModes.
|
||||
private void handleGameModeAndFlight(Player player, World world) {
|
||||
private void handleGameMode(Player player, World world) {
|
||||
|
||||
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
|
||||
if (mvWorld != null) {
|
||||
this.handleGameModeAndFlight(player, mvWorld);
|
||||
this.handleGameMode(player, mvWorld);
|
||||
} else {
|
||||
this.plugin.log(Level.FINER, "Not handling gamemode and flight for world '" + world.getName()
|
||||
this.plugin.log(Level.FINER, "Not handling gamemode for world '" + world.getName()
|
||||
+ "' not managed by Multiverse.");
|
||||
}
|
||||
}
|
||||
@@ -333,40 +330,28 @@ public class MVPlayerListener implements Listener {
|
||||
* @param player The {@link Player}.
|
||||
* @param world The world the player is in.
|
||||
*/
|
||||
public void handleGameModeAndFlight(final Player player, final MultiverseWorld world) {
|
||||
public void handleGameMode(final Player player, final MultiverseWorld world) {
|
||||
// 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.
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!MVPlayerListener.this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
||||
// 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()) {
|
||||
Logging.fine("Handling gamemode for player: %s, Changing to %s", player.getName(), world.getGameMode().toString());
|
||||
Logging.finest("From World: %s", player.getWorld());
|
||||
Logging.finest("To World: %s", world);
|
||||
player.setGameMode(world.getGameMode());
|
||||
// Check if their flight mode should change
|
||||
// TODO need a override permission for this
|
||||
if (player.getAllowFlight() && !world.getAllowFlight() && player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setAllowFlight(false);
|
||||
if (player.isFlying()) {
|
||||
player.setFlying(false);
|
||||
}
|
||||
} else if (world.getAllowFlight()) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||
player.setAllowFlight(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Logging.fine("The gamemode/allowfly was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
|
||||
player.getName(), player.getWorld().getName(), world.getName());
|
||||
}
|
||||
// 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()) {
|
||||
Logging.fine("Handling gamemode for player: %s, Changing to %s", player.getName(), world.getGameMode().toString());
|
||||
Logging.finest("From World: %s", player.getWorld());
|
||||
Logging.finest("To World: %s", world);
|
||||
player.setGameMode(world.getGameMode());
|
||||
} else {
|
||||
MVPlayerListener.this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
|
||||
Logging.fine("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());
|
||||
}
|
||||
}
|
||||
}, 1L);
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.onarandombox.MultiverseCore.localization;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Multiverse 2 LazyMessageProvider
|
||||
* <p>
|
||||
* This interface describes a Multiverse-MessageProvider that only loads locales when they're needed.
|
||||
*/
|
||||
public interface LazyLocaleMessageProvider extends MessageProvider {
|
||||
|
||||
/**
|
||||
* Loads a localization for a specified {@link Locale}.
|
||||
* <p>
|
||||
* If that localization is already loaded, this method will reload it.
|
||||
*
|
||||
* @param locale The desired {@link Locale}.
|
||||
* @throws LocalizationLoadingException When an error occurs while trying to load the specified localization.
|
||||
*/
|
||||
void loadLocale(Locale locale) throws LocalizationLoadingException;
|
||||
|
||||
/**
|
||||
* Retrieves all loaded localizations.
|
||||
*
|
||||
* @return A {@link Set} of {@link Locale}s whose localizations are currently loaded.
|
||||
*/
|
||||
Set<Locale> getLoadedLocales();
|
||||
|
||||
/**
|
||||
* Detects if a localization is loaded for the specified {@link Locale}.
|
||||
*
|
||||
* @param locale The {@link Locale}.
|
||||
* @return Whether a localization is loaded for the specified {@link Locale}.
|
||||
*/
|
||||
boolean isLocaleLoaded(Locale locale);
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.onarandombox.MultiverseCore.localization;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Thrown when an error occurs while a localization is loaded.
|
||||
*/
|
||||
public class LocalizationLoadingException extends IOException {
|
||||
private final Locale locale;
|
||||
|
||||
public LocalizationLoadingException(Locale locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public LocalizationLoadingException(String message, Locale locale) {
|
||||
super(message);
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public LocalizationLoadingException(Throwable cause, Locale locale) {
|
||||
super(cause);
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public LocalizationLoadingException(String message, Throwable cause, Locale locale) {
|
||||
super(message, cause);
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The locale we were trying to load.
|
||||
*/
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return super.getMessage() + " (While trying to load localization for locale " + getLocale() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.onarandombox.MultiverseCore.localization;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Multiverse 2 MessageProvider
|
||||
* <p>
|
||||
* This interface describes a Multiverse-MessageProvider.
|
||||
*/
|
||||
public interface MessageProvider {
|
||||
/**
|
||||
* The default locale.
|
||||
*/
|
||||
Locale DEFAULT_LOCALE = Locale.ENGLISH;
|
||||
|
||||
/**
|
||||
* Returns a message (as {@link String}) for the specified key (as {@link MultiverseMessage}).
|
||||
*
|
||||
* @param key The key
|
||||
* @param args Args for String.format()
|
||||
* @return The message
|
||||
*/
|
||||
String getMessage(MultiverseMessage key, Object... args);
|
||||
|
||||
/**
|
||||
* Returns a message (as {@link String}) in a specified {@link Locale} for the specified key (as {@link MultiverseMessage}).
|
||||
*
|
||||
* @param key The Key
|
||||
* @param locale The {@link Locale}
|
||||
* @param args Args for String.format()
|
||||
* @return The message
|
||||
*/
|
||||
String getMessage(MultiverseMessage key, Locale locale, Object... args);
|
||||
|
||||
/**
|
||||
* @return the Locale this MessageProvider is currently using.
|
||||
*/
|
||||
Locale getLocale();
|
||||
|
||||
/**
|
||||
* Sets the locale for this MessageProvider.
|
||||
*
|
||||
* @param locale The new {@link Locale}.
|
||||
*/
|
||||
void setLocale(Locale locale);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.onarandombox.MultiverseCore.localization;
|
||||
|
||||
/**
|
||||
* Multiverse 2 MessageProviding
|
||||
* <p>
|
||||
* This interface is implemented by classes that use a {@link MessageProvider}.
|
||||
*/
|
||||
public interface MessageProviding {
|
||||
/**
|
||||
* @return The {@link MessageProvider} used by the Core.
|
||||
*/
|
||||
MessageProvider getMessageProvider();
|
||||
|
||||
/**
|
||||
* Sets the {@link MessageProvider} used by the core.
|
||||
*
|
||||
* @param provider The new {@link MessageProvider}. Must not be null!
|
||||
*/
|
||||
void setMessageProvider(MessageProvider provider);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.onarandombox.MultiverseCore.localization;
|
||||
|
||||
|
||||
/**
|
||||
* An enum containing all messages/strings used by Multiverse.
|
||||
*/
|
||||
public enum MultiverseMessage {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
TEST_STRING("a test-string from the enum"),
|
||||
|
||||
//// Command handling error messages
|
||||
CH_PLUGIN_DISABLED("This plugin is disabled!"),
|
||||
CH_INTERNAL_ERROR("&cAn internal error occurred when attempting to perform this command."),
|
||||
CH_ADMIN_DEBUG("&cDetails were printed to the server console and logs, please add that to your bug report."),
|
||||
CH_USER_DEBUG("&cTry again and contact the server owner or an admin if this problem persists."),
|
||||
|
||||
//// Not MV world message
|
||||
GENERIC_NOT_MV_WORLD("Multiverse doesn't know about &3%s&f yet.\nType &3/mv import ?&f for help!"),
|
||||
|
||||
//// Commands
|
||||
// Anchor Command
|
||||
CMD_ANCHOR_NOLISTPERM("&cYou don't have the permission to list anchors!"),
|
||||
CMD_ANCHOR_LISTHEADER("&d====[ Multiverse Anchor List ]===="),
|
||||
CMD_ANCHOR_NOMATCH("&cSorry... &fNo anchors matched your filter: &b%s"),
|
||||
CMD_ANCHOR_NODEF("&cSorry... &fNo anchors were defined."),
|
||||
CMD_ANCHOR_PAGEHEADER("&b Page %d of %d"),
|
||||
CMD_ANCHOR_NODELPERM("&cYou don't have the permission to delete anchors!"),
|
||||
CMD_ANCHOR_NOCREATEPERM("&cYou don't have the permission to create anchors!"),
|
||||
CMD_ANCHOR_DELSUCCESS("Anchor '%s' was successfully &cdeleted!"),
|
||||
CMD_ANCHOR_DELFAIL("Anchor '%s' was &cNOT&f deleted!"),
|
||||
CMD_ANCHOR_CREATESUCCESS("Anchor '%s' was &asuccessfully&f created!"),
|
||||
CMD_ANCHOR_CREATEFAIL("Anchor '%s' was &cNOT&f created!"),
|
||||
CMD_ANCHOR_CONSOLECREATE("You must be a player to create Anchors!"),
|
||||
// Check Command
|
||||
CMD_CHECK_NOSUCHPLAYER("Could not find player &d%s&f\nAre they online?"),
|
||||
CMD_CHECK_NOSUCHDEST("You asked if '%s' could go to '&d%s&f', but I couldn't find a Destination of that name? Did you type it correctly?"),
|
||||
// Clone Command
|
||||
CMD_CLONE_NOSUCHWORLD("Sorry, Multiverse doesn't know about world '%s', so we can't clone it!\nCheck the &a/mv list&f command to verify it is listed."),
|
||||
CMD_CLONE_SUCCESS("&aWorld Cloned!"),
|
||||
CMD_CLONE_FAIL("&cWorld could NOT be cloned!"),
|
||||
// Config Command
|
||||
CMD_CONFIG_SETFAIL("&cSetting '%s' to '%s' failed!"),
|
||||
CMD_CONFIG_SUCCESS("&aSUCCESS!&f Values were updated successfully!"),
|
||||
CMD_CONFIG_FAIL("&cFAIL!&f Check your console for details!"),
|
||||
// Create Command
|
||||
CMD_CREATE_WORLDEXISTS("&cMultiverse cannot create &n&6another&r&c world named '%s'."),
|
||||
CMD_CREATE_FILEEXISTS("&cA Folder/World already exists with this name!\n&cIf you are confident it is a world you can import it with &a/mv import"),
|
||||
CMD_CREATE_INVALIDENV("&cThat is not a valid environment."),
|
||||
CMD_CREATE_INVALIDTYPE("&cThat is not a valid World Type."),
|
||||
CMD_CREATE_INVALIDGEN("Invalid generator '%s'! &cAborting world creation."),
|
||||
CMD_CREATE_START("Starting creation of world '%s'..."),
|
||||
CMD_CREATE_COMPLETE("Complete!"),
|
||||
CMD_CREATE_FAILED("FAILED."),
|
||||
// Generator Command
|
||||
CMD_GENERATOR_LISTHEADER("&b--- Loaded Generator Plugins ---"),
|
||||
CMD_GENERATOR_NOGENSFOUND("&cNo Generator Plugins found."),
|
||||
// List Command
|
||||
CMD_LIST_NAME("World Listing"),
|
||||
CMD_LIST_DESC("Displays a listing of all worlds that you can enter."),
|
||||
CMD_LIST_TITLE("Multiverse World List"),
|
||||
CMD_LIST_NO_MATCH("No worlds matched your filter:"),
|
||||
|
||||
//// Listeners
|
||||
// PlayerListener
|
||||
LISTENER_PLAYER_LOSTACCESSPERM("[MV] - Sorry you can't be in this world anymore!"),
|
||||
|
||||
//// Permissions
|
||||
PERMS_NOACCESS_SELF("You don't have access to go here..."),
|
||||
PERMS_NOACCESS_OTHER("You can't send %s here..."),
|
||||
PERMS_NOACCESS_BLACKLIST_SELF("You don't have access to go to %s from %s"),
|
||||
PERMS_NOACCESS_BLACKLIST_OTHER("You don't have access to send %s from %s to %s"),
|
||||
|
||||
//// World purger
|
||||
PURGER_ENTITIESKILLED("%d entities purged from the world '%s'"),
|
||||
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
; // SUPPRESS CHECKSTYLE: Whitespace
|
||||
|
||||
private final String def;
|
||||
|
||||
MultiverseMessage(String def) {
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return This {@link MultiverseMessage}'s default-message
|
||||
*/
|
||||
public String getDefault() {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.onarandombox.MultiverseCore.localization;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Thrown when the requested localization is not found.
|
||||
*/
|
||||
public class NoSuchLocalizationException extends LocalizationLoadingException {
|
||||
|
||||
public NoSuchLocalizationException(Locale locale) {
|
||||
super(locale);
|
||||
}
|
||||
|
||||
public NoSuchLocalizationException(String message, Locale locale) {
|
||||
super(message, locale);
|
||||
}
|
||||
|
||||
public NoSuchLocalizationException(String message, Throwable cause, Locale locale) {
|
||||
super(message, cause, locale);
|
||||
}
|
||||
|
||||
public NoSuchLocalizationException(Throwable cause, Locale locale) {
|
||||
super(cause, locale);
|
||||
}
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
package com.onarandombox.MultiverseCore.localization;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
/**
|
||||
* The normal {@link MessageProvider}-implementation.
|
||||
*/
|
||||
public class SimpleMessageProvider implements LazyLocaleMessageProvider {
|
||||
private static final String LOCALIZATION_FOLDER_NAME = "localization";
|
||||
|
||||
// Regex 1: replace all single & with the section char
|
||||
private static final String FORMAT_PATTERN_1;
|
||||
private static final String FORMAT_REPL_1;
|
||||
static {
|
||||
StringBuilder formatBuilder = new StringBuilder("([^&])&([");
|
||||
for (ChatColor c : ChatColor.values())
|
||||
formatBuilder.append(c.getChar());
|
||||
FORMAT_PATTERN_1 = formatBuilder.append("])").toString();
|
||||
|
||||
FORMAT_REPL_1 = new StringBuilder().append("$1").append(ChatColor.COLOR_CHAR).append("$2").toString();
|
||||
}
|
||||
|
||||
// Regex 2: replace all double & with single &
|
||||
private static final String FORMAT_PATTERN_2 = "&&";
|
||||
private static final String FORMAT_REPL_2 = "&";
|
||||
|
||||
private final Map<Locale, Map<MultiverseMessage, String>> messages;
|
||||
private final MultiverseCore core;
|
||||
|
||||
private Locale locale = DEFAULT_LOCALE;
|
||||
|
||||
public SimpleMessageProvider(MultiverseCore core) {
|
||||
this.core = core;
|
||||
messages = new ConcurrentHashMap<Locale, Map<MultiverseMessage, String>>();
|
||||
|
||||
try {
|
||||
loadLocale(locale);
|
||||
} catch (NoSuchLocalizationException e) {
|
||||
// let's take the defaults from the enum!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a given {@link Locale} if and only if it wasn't already loaded.
|
||||
* @param locale The locale
|
||||
* @throws LocalizationLoadingException If the locale wasn't loaded successfully.
|
||||
*/
|
||||
public void maybeLoadLocale(Locale locale) throws LocalizationLoadingException {
|
||||
if (!isLocaleLoaded(locale)) {
|
||||
try {
|
||||
loadLocale(locale);
|
||||
} catch (NoSuchLocalizationException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (!isLocaleLoaded(locale))
|
||||
throw new LocalizationLoadingException("Couldn't load the localization: "
|
||||
+ locale.toString(), locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the specified string.
|
||||
* <p>
|
||||
* You can use {@code &} to get colors. To get an {@code &} in the output, you have to write {@code &&}.
|
||||
*
|
||||
* @param string The {@link String}.
|
||||
* @param args Args for {@link String#format(String, Object...)}.
|
||||
* @return The formatted string.
|
||||
*/
|
||||
public static String format(String string, Object... args) {
|
||||
// Replaces & with the Section character
|
||||
string = string.replaceAll(FORMAT_PATTERN_1, FORMAT_REPL_1).replaceAll(FORMAT_PATTERN_2, FORMAT_REPL_2);
|
||||
|
||||
return String.format(string, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void loadLocale(Locale l) throws NoSuchLocalizationException {
|
||||
messages.remove(l);
|
||||
|
||||
InputStream resstream = null;
|
||||
InputStream filestream = null;
|
||||
|
||||
try {
|
||||
try {
|
||||
filestream = new FileInputStream(new File(core.getDataFolder(), l.getLanguage() + ".yml"));
|
||||
} catch (FileNotFoundException e) {
|
||||
}
|
||||
try {
|
||||
resstream = core.getResource(new StringBuilder(LOCALIZATION_FOLDER_NAME)
|
||||
.append("/").append(l.getLanguage()).append(".yml").toString());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if ((resstream == null) && (filestream == null))
|
||||
throw new NoSuchLocalizationException(l);
|
||||
|
||||
Map<MultiverseMessage, String> stringsMap = new HashMap<MultiverseMessage, String>();
|
||||
FileConfiguration resconfig = (resstream == null) ? null : YamlConfiguration.loadConfiguration(resstream);
|
||||
FileConfiguration fileconfig = (filestream == null) ? null : YamlConfiguration.loadConfiguration(filestream);
|
||||
for (MultiverseMessage m : MultiverseMessage.values()) {
|
||||
String value = m.getDefault();
|
||||
|
||||
if (resconfig != null)
|
||||
value = resconfig.getString(m.toString(), value);
|
||||
if (fileconfig != null)
|
||||
value = fileconfig.getString(m.toString(), value);
|
||||
|
||||
stringsMap.put(m, value);
|
||||
}
|
||||
|
||||
messages.put(l, Collections.unmodifiableMap(stringsMap));
|
||||
} finally {
|
||||
if (filestream != null)
|
||||
try {
|
||||
filestream.close();
|
||||
} catch (IOException e) {
|
||||
// silently discard
|
||||
}
|
||||
if (resstream != null)
|
||||
try {
|
||||
resstream.close();
|
||||
} catch (IOException e) {
|
||||
// silently discard
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<Locale> getLoadedLocales() {
|
||||
return messages.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isLocaleLoaded(Locale l) {
|
||||
return messages.containsKey(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getMessage(MultiverseMessage key, Object... args) {
|
||||
if (!isLocaleLoaded(locale))
|
||||
return format(key.getDefault(), args);
|
||||
else
|
||||
return format(messages.get(locale).get(key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getMessage(MultiverseMessage key, Locale locale, Object... args) {
|
||||
try {
|
||||
maybeLoadLocale(locale);
|
||||
} catch (LocalizationLoadingException e) {
|
||||
e.printStackTrace();
|
||||
return getMessage(key);
|
||||
}
|
||||
return format(messages.get(locale).get(key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setLocale(Locale locale) {
|
||||
if (locale == null)
|
||||
throw new IllegalArgumentException("Can't set locale to null!");
|
||||
try {
|
||||
maybeLoadLocale(locale);
|
||||
} catch (LocalizationLoadingException e) {
|
||||
if (!locale.equals(DEFAULT_LOCALE))
|
||||
throw new IllegalArgumentException("Error while trying to load localization for the given Locale!", e);
|
||||
}
|
||||
|
||||
this.locale = locale;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Contains localization.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.localization;
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.permissions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
/**
|
||||
* Provides improved parent-child relationships for permissions. This is the standard implementation of {@link PermissionNode}.
|
||||
* <p>
|
||||
* Apparently parents override their children in Bukkit:
|
||||
* Let {@code permissionA} be a parent permission of {@code permissionB}, setting {@code permissionB} to {@code true}.
|
||||
* Now a player has {@code permissionA=true} and {@code permissionB=false}. Result: Both are {@code true}.
|
||||
* Another player has {@code permissionA=false} and {@code permissionB=true}. Result: Both are {@code false}.
|
||||
* <p>
|
||||
* This is completely useless for things like MV's world access permissions where you could for example want to deny
|
||||
* access to all worlds by default, with a few exceptions.
|
||||
* <p>
|
||||
* This class takes over all the permission hierarchy checks and provides a way that makes sense. In the
|
||||
* above examples, the effective permissions would be equal to the permissions that were set.
|
||||
*/
|
||||
public class HierarchyPermission implements PermissionNode {
|
||||
private final PermissionNode parent;
|
||||
private final Permission permission;
|
||||
|
||||
public HierarchyPermission(final PermissionNode parent, final String permission, final String description) {
|
||||
this.parent = parent;
|
||||
Permission p = Bukkit.getServer().getPluginManager().getPermission(permission);
|
||||
if (p == null)
|
||||
p = new Permission(permission, description, PermissionDefault.FALSE);
|
||||
else {
|
||||
p.getChildren().clear();
|
||||
//p.recalculatePermissibles(); // Not necessary because it's done automatically after setting the default
|
||||
p.setDefault(PermissionDefault.FALSE);
|
||||
}
|
||||
this.permission = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given {@link Permissible} has this {@link HierarchyPermission}.
|
||||
*
|
||||
* @param permissible The {@link Permissible} that might have the permission.
|
||||
* @return Whether it has the permission.
|
||||
*/
|
||||
public boolean has(Permissible permissible) {
|
||||
if (permissible.isPermissionSet(permission))
|
||||
return permissible.hasPermission(permission);
|
||||
|
||||
// ask the guy over there
|
||||
return parent.has(permissible);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.permissions;
|
||||
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a permission node with dynamically created children.
|
||||
*/
|
||||
public class PermissionCollection {
|
||||
private final PermissionNode root;
|
||||
private final Map<String, PermissionNode> elements;
|
||||
private final String prefix;
|
||||
private final String description;
|
||||
|
||||
public PermissionCollection(PermissionNode parent, String prefix, String description) {
|
||||
if (!prefix.endsWith("."))
|
||||
throw new IllegalArgumentException("The prefix must end with a dot!");
|
||||
this.root = new HierarchyPermission(parent, prefix + "*", description);
|
||||
this.elements = new HashMap<String, PermissionNode>();
|
||||
this.prefix = prefix;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given {@link Permissible} has a specified element permission.
|
||||
*
|
||||
* @param p The {@link Permissible}.
|
||||
* @param element The element.
|
||||
* @return Whether the {@link Permissible} has the permission.
|
||||
*/
|
||||
public boolean has(Permissible p, String element) {
|
||||
if (!this.elements.containsKey(element))
|
||||
this.elements.put(element, new HierarchyPermission(root, prefix + element, description));
|
||||
return this.elements.get(element).has(p);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.permissions;
|
||||
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
/**
|
||||
* A node in a permissions hierarchy.
|
||||
*
|
||||
* @see HierarchyPermission
|
||||
*/
|
||||
public interface PermissionNode {
|
||||
static final class OperatorDefault implements PermissionNode {
|
||||
@Override
|
||||
public boolean has(final Permissible permissible) {
|
||||
return permissible.isOp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This {@link HierarchyPermission} depends on the operator state. Ops have it, non-ops don't.
|
||||
*/
|
||||
PermissionNode OP_DEFAULT = new OperatorDefault();
|
||||
|
||||
/**
|
||||
* Checks whether a given {@link Permissible} has this node.
|
||||
*
|
||||
* @param permissible The {@link Permissible} that might have the permission.
|
||||
* @return Whether it has the permission.
|
||||
*/
|
||||
boolean has(Permissible permissible);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.permissions;
|
||||
|
||||
/**
|
||||
* Permission nodes.
|
||||
*/
|
||||
public class Permissions {
|
||||
protected Permissions() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@code multiverse.*} permission.
|
||||
*/
|
||||
public static final HierarchyPermission MV_ROOT = new HierarchyPermission(PermissionNode.OP_DEFAULT,
|
||||
"multiverse.*", "Provides access to all Multiverse features.");
|
||||
|
||||
/**
|
||||
* The {@code multiverse.access.*} family of permissions.
|
||||
*/
|
||||
public static final PermissionCollection ACCESS = new PermissionCollection(MV_ROOT, "multiverse.access.", "World access");
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Contains permissions utility classes.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.permissions;
|
||||
@@ -73,28 +73,28 @@ public class BlockSafety {
|
||||
|
||||
if (this.isSolidBlock(world.getBlockAt(actual).getType())
|
||||
|| this.isSolidBlock(upOne.getBlock().getType())) {
|
||||
Logging.finest("Error Here (Actual)? (%s)[%s]", actual.getBlock().getType(),
|
||||
Logging.finer("Error Here (Actual)? (%s)[%s]", actual.getBlock().getType(),
|
||||
this.isSolidBlock(actual.getBlock().getType()));
|
||||
Logging.finest("Error Here (upOne)? (%s)[%s]", upOne.getBlock().getType(),
|
||||
Logging.finer("Error Here (upOne)? (%s)[%s]", upOne.getBlock().getType(),
|
||||
this.isSolidBlock(upOne.getBlock().getType()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
|
||||
Logging.finest("Error Here (downOne)? (%s)[%s]", downOne.getBlock().getType(),
|
||||
Logging.finer("Error Here (downOne)? (%s)[%s]", downOne.getBlock().getType(),
|
||||
this.isSolidBlock(downOne.getBlock().getType()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (downOne.getBlock().getType() == Material.FIRE) {
|
||||
Logging.finest("There's fire below! (%s)[%s]", actual.getBlock().getType(),
|
||||
Logging.finer("There's fire below! (%s)[%s]", actual.getBlock().getType(),
|
||||
this.isSolidBlock(actual.getBlock().getType()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isBlockAboveAir(actual)) {
|
||||
Logging.finest("Is block above air [%s]", isBlockAboveAir(actual));
|
||||
Logging.finest("Has 2 blocks of water below [%s]", this.hasTwoBlocksofWaterBelow(actual));
|
||||
Logging.finer("Is block above air [%s]", isBlockAboveAir(actual));
|
||||
Logging.finer("Has 2 blocks of water below [%s]", this.hasTwoBlocksofWaterBelow(actual));
|
||||
return this.hasTwoBlocksofWaterBelow(actual);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -7,10 +7,13 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
@@ -28,11 +31,16 @@ public class FileUtils {
|
||||
* @return true if the folder was successfully deleted.
|
||||
*/
|
||||
public static boolean deleteFolder(File file) {
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.deleteDirectory(file);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Logging.warning(e.getMessage());
|
||||
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()) {
|
||||
ret = ret && deleteFolder(f);
|
||||
}
|
||||
}
|
||||
return ret && file.delete();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -44,11 +52,16 @@ public class FileUtils {
|
||||
* @return true if the contents were successfully deleted
|
||||
*/
|
||||
public static boolean deleteFolderContents(File file) {
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.cleanDirectory(file);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Logging.warning(e.getMessage());
|
||||
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()) {
|
||||
ret = ret && deleteFolder(f);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -64,12 +77,46 @@ public class FileUtils {
|
||||
* @return if it had success
|
||||
*/
|
||||
public static boolean copyFolder(File source, File target, Logger log) {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.copyDirectory(source, target);
|
||||
if (source.isDirectory()) {
|
||||
|
||||
if (!target.exists())
|
||||
target.mkdir();
|
||||
|
||||
String[] children = source.list();
|
||||
// for (int i=0; i<children.length; i++) {
|
||||
for (String child : children) {
|
||||
copyFolder(new File(source, child), new File(target, child), log);
|
||||
}
|
||||
} else {
|
||||
in = new FileInputStream(source);
|
||||
out = new FileOutputStream(target);
|
||||
|
||||
byte[] buf = new byte[COPY_BLOCK_SIZE];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (FileNotFoundException e) {
|
||||
log.warning("Exception while copying file: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
log.warning(e.getMessage());
|
||||
return false;
|
||||
log.warning("Exception while copying file: " + e.getMessage());
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.onarandombox.MultiverseCore.localization.MessageProviding;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -20,10 +22,12 @@ import java.util.Map;
|
||||
* The default-implementation of {@link MultiverseMessaging}.
|
||||
*/
|
||||
public class MVMessaging implements MultiverseMessaging {
|
||||
private final MessageProviding msgProviding;
|
||||
private Map<String, Long> sentList;
|
||||
private int cooldown;
|
||||
|
||||
public MVMessaging() {
|
||||
public MVMessaging(MessageProviding msgProviding) {
|
||||
this.msgProviding = msgProviding;
|
||||
this.sentList = new HashMap<String, Long>();
|
||||
this.cooldown = 5000; // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
@@ -50,7 +54,6 @@ public class MVMessaging implements MultiverseMessaging {
|
||||
@Override
|
||||
public boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown) {
|
||||
if (!(sender instanceof Player) || ignoreCooldown) {
|
||||
|
||||
sendMessages(sender, messages);
|
||||
return true;
|
||||
}
|
||||
@@ -90,4 +93,20 @@ public class MVMessaging implements MultiverseMessaging {
|
||||
public int getCooldown() {
|
||||
return cooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean sendMessage(CommandSender sender, MultiverseMessage message, Object... args) {
|
||||
return this.sendMessage(sender, message, true, args); // TODO what is a good default value?
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean sendMessage(CommandSender sender, MultiverseMessage message, boolean ignoreCooldown, Object...args) {
|
||||
return this.sendMessage(sender, this.msgProviding.getMessageProvider().getMessage(message, args), ignoreCooldown);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.permissions.Permissions;
|
||||
import com.pneumaticraft.commandhandler.PermissionsInterface;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@@ -104,15 +103,18 @@ public class MVPermissions implements PermissionsInterface {
|
||||
this.plugin.log(Level.FINEST, "EnforceAccess is OFF. Player was allowed in " + w.getAlias());
|
||||
return true;
|
||||
}
|
||||
return Permissions.ACCESS.has(p, w.getName());
|
||||
return this.hasPermission(p, "multiverse.access." + w.getName(), false);
|
||||
}
|
||||
|
||||
private boolean canEnterLocation(Player p, Location l) {
|
||||
if (l == null)
|
||||
if (l == null) {
|
||||
return false;
|
||||
|
||||
}
|
||||
String worldName = l.getWorld().getName();
|
||||
return this.plugin.getMVWorldManager().isMVWorld(worldName) && Permissions.ACCESS.has(p, worldName);
|
||||
if (!this.plugin.getMVWorldManager().isMVWorld(worldName)) {
|
||||
return false;
|
||||
}
|
||||
return this.hasPermission(p, "multiverse.access." + worldName, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.fernferret.allpay.commons.GenericBank;
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -231,11 +233,10 @@ public class PermissionTools {
|
||||
// Actual checks
|
||||
if (toWorld != null) {
|
||||
if (!this.plugin.getMVPerms().canEnterWorld(teleporterPlayer, toWorld)) {
|
||||
if (teleportee.equals(teleporter)) {
|
||||
teleporter.sendMessage("You don't have access to go here...");
|
||||
} else {
|
||||
teleporter.sendMessage("You can't send " + teleportee.getName() + " here...");
|
||||
}
|
||||
if (teleportee.equals(teleporter))
|
||||
this.plugin.getMessaging().sendMessage(teleporter, MultiverseMessage.PERMS_NOACCESS_SELF);
|
||||
else
|
||||
this.plugin.getMessaging().sendMessage(teleporter, MultiverseMessage.PERMS_NOACCESS_OTHER, teleportee.getName());
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -246,35 +247,26 @@ public class PermissionTools {
|
||||
}
|
||||
if (fromWorld != null) {
|
||||
if (fromWorld.getWorldBlacklist().contains(toWorld.getName())) {
|
||||
if (teleportee.equals(teleporter)) {
|
||||
teleporter.sendMessage("You don't have access to go to " + toWorld.getColoredWorldString() + " from " + fromWorld.getColoredWorldString());
|
||||
} else {
|
||||
teleporter.sendMessage("You don't have access to send " + teleportee.getName() + " from "
|
||||
+ fromWorld.getColoredWorldString() + " to " + toWorld.getColoredWorldString());
|
||||
}
|
||||
if (teleportee.equals(teleporter))
|
||||
this.plugin.getMessaging().sendMessage(teleporter, MultiverseMessage.PERMS_NOACCESS_BLACKLIST_SELF, toWorld.getColoredWorldString(), fromWorld.getColoredWorldString());
|
||||
else
|
||||
this.plugin.getMessaging().sendMessage(teleporter, MultiverseMessage.PERMS_NOACCESS_BLACKLIST_OTHER, teleportee.getName(), fromWorld.getColoredWorldString(), toWorld.getColoredWorldString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a player can bypass the player limit.
|
||||
*
|
||||
* @param toWorld The world travelling to.
|
||||
* @param teleporter The player that initiated the teleport.
|
||||
* @param teleportee The player travelling.
|
||||
* @return True if they can bypass the player limit.
|
||||
*/
|
||||
|
||||
public boolean playerCanBypassPlayerLimit(MultiverseWorld toWorld, CommandSender teleporter, Player teleportee) {
|
||||
|
||||
if (teleporter == null) {
|
||||
teleporter = teleportee;
|
||||
}
|
||||
|
||||
|
||||
if (!(teleporter instanceof Player)) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
MVPermissions perms = plugin.getMVPerms();
|
||||
if (perms.hasPermission(teleportee, "mv.bypass.playerlimit." + toWorld.getName(), false)) {
|
||||
return true;
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Animals;
|
||||
@@ -18,15 +19,13 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Golem;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Squid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Utility class that removes animals from worlds that don't belong there.
|
||||
@@ -35,16 +34,8 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
|
||||
private MultiverseCore plugin;
|
||||
|
||||
private Class<Entity> ambientClass = null;
|
||||
|
||||
public SimpleWorldPurger(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
Class entityClass = Class.forName("org.bukkit.entity.Ambient");
|
||||
if (Entity.class.isAssignableFrom(entityClass)) {
|
||||
ambientClass = entityClass;
|
||||
}
|
||||
} catch (ClassNotFoundException ignore) { }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,53 +87,28 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
int projectilesKilled = 0;
|
||||
int entitiesKilled = 0;
|
||||
boolean specifiedAll = thingsToKill.contains("ALL");
|
||||
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
|
||||
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
|
||||
List<Entity> worldEntities = world.getEntities();
|
||||
List<LivingEntity> livingEntities = new ArrayList<LivingEntity>(worldEntities.size());
|
||||
List<Projectile> projectiles = new ArrayList<Projectile>(worldEntities.size());
|
||||
for (final Entity e : worldEntities) {
|
||||
if (e instanceof Projectile) {
|
||||
final Projectile p = (Projectile) e;
|
||||
if (p.getShooter() != null) {
|
||||
projectiles.add((Projectile) e);
|
||||
}
|
||||
} else if (e instanceof LivingEntity) {
|
||||
livingEntities.add((LivingEntity) e);
|
||||
}
|
||||
}
|
||||
for (final LivingEntity e : livingEntities) {
|
||||
for (Entity e : world.getEntities()) {
|
||||
if (killDecision(e, thingsToKill, negateAnimals, negateMonsters, specifiedAnimals, specifiedMonsters)) {
|
||||
final Iterator<Projectile> it = projectiles.iterator();
|
||||
while (it.hasNext()) {
|
||||
final Projectile p = it.next();
|
||||
if (p.getShooter().equals(e)) {
|
||||
p.remove();
|
||||
it.remove();
|
||||
projectilesKilled++;
|
||||
}
|
||||
}
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
}
|
||||
}
|
||||
if (sender != null) {
|
||||
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "' along with " + projectilesKilled + " projectiles that belonged to them.");
|
||||
}
|
||||
if (sender != null)
|
||||
this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.PURGER_ENTITIESKILLED, entitiesKilled, world.getName());
|
||||
}
|
||||
|
||||
private boolean killDecision(Entity e, List<String> thingsToKill, boolean negateAnimals,
|
||||
boolean negateMonsters, boolean specifiedAnimals, boolean specifiedMonsters) {
|
||||
boolean negate = false;
|
||||
boolean specified = false;
|
||||
if (e instanceof Golem || e instanceof Squid || e instanceof Animals
|
||||
|| (ambientClass != null && ambientClass.isInstance(e))) {
|
||||
if (e instanceof Golem || e instanceof Squid || e instanceof Animals) {
|
||||
// it's an animal
|
||||
if (specifiedAnimals && !negateAnimals) {
|
||||
Logging.finest("Removing an entity because I was told to remove all animals in world %s: %s", e.getWorld().getName(), e);
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all animals: " + e);
|
||||
return true;
|
||||
}
|
||||
if (specifiedAnimals)
|
||||
@@ -151,7 +117,7 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
} else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
|
||||
// it's a monster
|
||||
if (specifiedMonsters && !negateMonsters) {
|
||||
Logging.finest("Removing an entity because I was told to remove all monsters in world %s: %s", e.getWorld().getName(), e);
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
|
||||
return true;
|
||||
}
|
||||
if (specifiedMonsters)
|
||||
@@ -163,14 +129,14 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
if (type != null && type.equals(e.getType())) {
|
||||
specified = true;
|
||||
if (!negate) {
|
||||
Logging.finest("Removing an entity because it WAS specified and we are NOT negating in world %s: %s", e.getWorld().getName(), e);
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because it WAS specified and we are NOT negating: " + e);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!specified && negate) {
|
||||
Logging.finest("Removing an entity because it was NOT specified and we ARE negating in world %s: %s", e.getWorld().getName(), e);
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because it was NOT specified and we ARE negating: " + e);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Wraps calls that could result in exceptions that are not Multiverse's fault.
|
||||
*/
|
||||
public class UnsafeCallWrapper {
|
||||
private final Core core;
|
||||
|
||||
public UnsafeCallWrapper(Core core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps calls that could result in exceptions that are not Multiverse's fault.
|
||||
*
|
||||
* @param callable The potentially unsafe call.
|
||||
* @param plugin The plugin that's probably the culprit.
|
||||
* @param action What MV was attempting to do (error message, format string).
|
||||
* @param formatArgs The formatting arguments for the error message.
|
||||
* The exception that was thrown will be appended to these objects.
|
||||
* @param <T> The type of the return value.
|
||||
* @return The return value or null if the call failed.
|
||||
*/
|
||||
public <T> T wrap(Callable<T> callable, String plugin, String action, Object... formatArgs) {
|
||||
try {
|
||||
// We're ready to catch you! JUMP!
|
||||
return callable.call();
|
||||
} catch (Throwable t) {
|
||||
Object[] actualFormatArgs = new Object[formatArgs.length + 1];
|
||||
System.arraycopy(formatArgs, 0, actualFormatArgs, 0, formatArgs.length);
|
||||
actualFormatArgs[formatArgs.length] = t;
|
||||
Logging.warning(action, actualFormatArgs);
|
||||
Logging.warning("This is a bug in %s, NOT a bug in Multiverse!", plugin);
|
||||
if (core.getMVConfig().getGlobalDebug() >= 1)
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ public class VaultHandler implements Listener {
|
||||
|
||||
private boolean setupVaultEconomy() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||
final RegisteredServiceProvider<Economy> economyProvider =
|
||||
Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
final RegisteredServiceProvider<Economy> economyProvider
|
||||
= Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
Logging.fine("Vault economy enabled.");
|
||||
economy = economyProvider.getProvider();
|
||||
@@ -41,9 +41,6 @@ public class VaultHandler implements Listener {
|
||||
return (economy != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for Vault plugin events.
|
||||
*/
|
||||
private class VaultListener implements Listener {
|
||||
@EventHandler
|
||||
private void vaultEnabled(PluginEnableEvent event) {
|
||||
|
||||
@@ -10,7 +10,6 @@ package com.onarandombox.MultiverseCore.utils;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.WorldProperties;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
@@ -42,7 +41,6 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -54,14 +52,14 @@ public class WorldManager implements MVWorldManager {
|
||||
private final MultiverseCore plugin;
|
||||
private final WorldPurger worldPurger;
|
||||
private final Map<String, MultiverseWorld> worlds;
|
||||
private Map<String, WorldProperties> worldsFromTheConfig;
|
||||
private Map<String, MVWorld> worldsFromTheConfig;
|
||||
private FileConfiguration configWorlds = null;
|
||||
private Map<String, String> defaultGens;
|
||||
private String firstSpawn;
|
||||
|
||||
public WorldManager(MultiverseCore core) {
|
||||
this.plugin = core;
|
||||
this.worldsFromTheConfig = new HashMap<String, WorldProperties>();
|
||||
this.worldsFromTheConfig = new HashMap<String, MVWorld>();
|
||||
this.worlds = new ConcurrentHashMap<String, MultiverseWorld>();
|
||||
this.worldPurger = new SimpleWorldPurger(plugin);
|
||||
}
|
||||
@@ -209,10 +207,8 @@ public class WorldManager implements MVWorldManager {
|
||||
}
|
||||
|
||||
// Important: doLoad() needs the MVWorld-object in worldsFromTheConfig
|
||||
if (!worldsFromTheConfig.containsKey(name)) {
|
||||
WorldProperties props = new WorldProperties(useSpawnAdjust, env);
|
||||
worldsFromTheConfig.put(name, props);
|
||||
}
|
||||
if (!worldsFromTheConfig.containsKey(name))
|
||||
worldsFromTheConfig.put(name, new MVWorld(useSpawnAdjust));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Loading World & Settings - '").append(name).append("'");
|
||||
@@ -242,21 +238,16 @@ public class WorldManager implements MVWorldManager {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ChunkGenerator getChunkGenerator(String generator, final String generatorID, final String worldName) {
|
||||
public ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) {
|
||||
if (generator == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
|
||||
Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
|
||||
if (myPlugin == null) {
|
||||
return null;
|
||||
} else {
|
||||
return plugin.getUnsafeCallWrapper().wrap(new Callable<ChunkGenerator>() {
|
||||
@Override
|
||||
public ChunkGenerator call() throws Exception {
|
||||
return myPlugin.getDefaultWorldGenerator(worldName, generatorID);
|
||||
}
|
||||
}, myPlugin.getName(), "Failed to get the default chunk generator: %s");
|
||||
return myPlugin.getDefaultWorldGenerator(worldName, generatorID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,10 +308,12 @@ public class WorldManager implements MVWorldManager {
|
||||
@Override
|
||||
public boolean unloadWorld(String name) {
|
||||
if (this.worlds.containsKey(name)) {
|
||||
this.worldsFromTheConfig.get(name).cacheVirtualProperties();
|
||||
if (this.unloadWorldFromBukkit(name, true)) {
|
||||
this.worlds.remove(name);
|
||||
Logging.info("World '%s' was unloaded from memory.", name);
|
||||
|
||||
this.worldsFromTheConfig.get(name).tearDown();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
Logging.warning("World '%s' could not be unloaded. Is it a default world?", name);
|
||||
@@ -362,32 +355,21 @@ public class WorldManager implements MVWorldManager {
|
||||
}
|
||||
|
||||
private boolean doLoad(String name) {
|
||||
return doLoad(name, false, null);
|
||||
return doLoad(name, false);
|
||||
}
|
||||
|
||||
private boolean doLoad(String name, boolean ignoreExists, WorldType type) {
|
||||
private boolean doLoad(String name, boolean ignoreExists) {
|
||||
if (!worldsFromTheConfig.containsKey(name))
|
||||
throw new IllegalArgumentException("That world doesn't exist!");
|
||||
|
||||
final WorldProperties world = worldsFromTheConfig.get(name);
|
||||
final WorldCreator creator = WorldCreator.name(name);
|
||||
MVWorld world = worldsFromTheConfig.get(name);
|
||||
WorldCreator creator = WorldCreator.name(name);
|
||||
|
||||
creator.environment(world.getEnvironment()).seed(world.getSeed());
|
||||
if (type != null) {
|
||||
creator.type(type);
|
||||
}
|
||||
|
||||
boolean generatorSuccess = true;
|
||||
if ((world.getGenerator() != null) && (!world.getGenerator().equals("null")))
|
||||
generatorSuccess = null != plugin.getUnsafeCallWrapper().wrap(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
creator.generator(world.getGenerator());
|
||||
return new Object();
|
||||
}
|
||||
}, "the generator plugin", "Failed to set the generator for world '%s' to '%s': %s", name, world.getGenerator());
|
||||
creator.generator(world.getGenerator());
|
||||
|
||||
return generatorSuccess && doLoad(creator, ignoreExists);
|
||||
return doLoad(creator, ignoreExists);
|
||||
}
|
||||
|
||||
private boolean doLoad(WorldCreator creator, boolean ignoreExists) {
|
||||
@@ -403,7 +385,7 @@ public class WorldManager implements MVWorldManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
WorldProperties mvworld = worldsFromTheConfig.get(worldName);
|
||||
MVWorld mvworld = worldsFromTheConfig.get(worldName);
|
||||
World cbworld;
|
||||
try {
|
||||
cbworld = creator.createWorld();
|
||||
@@ -412,9 +394,9 @@ public class WorldManager implements MVWorldManager {
|
||||
brokenWorld(worldName);
|
||||
return false;
|
||||
}
|
||||
MVWorld world = new MVWorld(plugin, cbworld, mvworld);
|
||||
this.worldPurger.purgeWorld(world);
|
||||
this.worlds.put(worldName, world);
|
||||
mvworld.init(cbworld, plugin);
|
||||
this.worldPurger.purgeWorld(mvworld);
|
||||
this.worlds.put(worldName, mvworld);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -654,7 +636,7 @@ public class WorldManager implements MVWorldManager {
|
||||
this.worlds.clear();
|
||||
}
|
||||
|
||||
for (Map.Entry<String, WorldProperties> entry : worldsFromTheConfig.entrySet()) {
|
||||
for (Map.Entry<String, MVWorld> entry : worldsFromTheConfig.entrySet()) {
|
||||
if (worlds.containsKey(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
@@ -714,23 +696,31 @@ public class WorldManager implements MVWorldManager {
|
||||
// load world-objects
|
||||
Stack<String> worldKeys = new Stack<String>();
|
||||
worldKeys.addAll(this.configWorlds.getConfigurationSection("worlds").getKeys(false));
|
||||
Map<String, WorldProperties> newWorldsFromTheConfig = new HashMap<String, WorldProperties>();
|
||||
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 WorldProperties)) {
|
||||
if ((obj != null) && (obj instanceof MVWorld)) {
|
||||
String worldName = key.replaceAll(String.valueOf(SEPARATOR), ".");
|
||||
WorldProperties props = (WorldProperties) obj;
|
||||
MVWorld mvWorld = null;
|
||||
if (this.worldsFromTheConfig.containsKey(worldName)) {
|
||||
// Object-Recycling :D
|
||||
// TODO Why is is checking worldsFromTheConfig and then getting from worlds? So confused... (DTM)
|
||||
MVWorld mvWorld = (MVWorld) this.worlds.get(worldName);
|
||||
mvWorld = (MVWorld) this.worlds.get(worldName);
|
||||
if (mvWorld != null) {
|
||||
mvWorld.copyValues((WorldProperties) obj);
|
||||
mvWorld.copyValues((MVWorld) obj);
|
||||
}
|
||||
}
|
||||
newWorldsFromTheConfig.put(worldName, props);
|
||||
if (mvWorld == null) {
|
||||
// we have to use a new one
|
||||
World cbworld = this.plugin.getServer().getWorld(worldName);
|
||||
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);
|
||||
@@ -752,7 +742,7 @@ public class WorldManager implements MVWorldManager {
|
||||
try {
|
||||
this.configWorlds.options().pathSeparator(SEPARATOR);
|
||||
this.configWorlds.set("worlds", null);
|
||||
for (Map.Entry<String, WorldProperties> entry : worldsFromTheConfig.entrySet()) {
|
||||
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"));
|
||||
@@ -807,10 +797,9 @@ public class WorldManager implements MVWorldManager {
|
||||
|
||||
world.setSeed(theSeed);
|
||||
}
|
||||
WorldType type = world.getWorldType();
|
||||
|
||||
if (this.deleteWorld(name, false, false)) {
|
||||
this.doLoad(name, true, type);
|
||||
this.doLoad(name, true);
|
||||
SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
|
||||
Location newSpawn = world.getSpawnLocation();
|
||||
// Send all players that were in the old world, BACK to it!
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
TEST_STRING: 'a test-string from the resource'
|
||||
|
||||
# Generic Strings
|
||||
GENERIC_SORRY: 'Sorry...'
|
||||
GENERIC_PAGE: 'Page'
|
||||
GENERIC_OF: 'of'
|
||||
GENERIC_UNLOADED: 'UNLOADED'
|
||||
GENERIC_PLUGIN_DISABLED: 'This plugin is Disabled!'
|
||||
|
||||
# Errors
|
||||
ERROR_LOAD: 'Your configs were not loaded. Very little will function in Multiverse.'
|
||||
|
||||
|
||||
## Commands
|
||||
# List Command
|
||||
LIST_NAME: 'World Listing'
|
||||
LIST_DESC: 'Displays a listing of all worlds that you can enter.'
|
||||
LIST_TITLE: 'Multiverse World List'
|
||||
LIST_NO_MATCH: 'No worlds matched your filter:'
|
||||
|
||||
@@ -215,20 +215,3 @@ commands:
|
||||
description: Reduces startup messages
|
||||
usage: |
|
||||
/<command> [true|false]
|
||||
|
||||
mvgamerule:
|
||||
description: Sets a gamerule.
|
||||
usage: |
|
||||
/<command> {RULE} {VALUE} [WORLD]
|
||||
mvrule:
|
||||
description: Sets a gamerule.
|
||||
usage: |
|
||||
/<command> {RULE} {VALUE} [WORLD]
|
||||
mvgamerules:
|
||||
description: Lists the gamerules.
|
||||
usage: |
|
||||
/<command> [WORLD]
|
||||
mvrules:
|
||||
description: Lists the gamerules.
|
||||
usage: |
|
||||
/<command> [WORLD]
|
||||
+12
-9
@@ -5,11 +5,17 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore;
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -22,12 +28,9 @@ import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
||||
+14
-12
@@ -1,9 +1,13 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -20,13 +24,11 @@ import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
||||
@@ -0,0 +1,204 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Server;
|
||||
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.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.localization.LazyLocaleMessageProvider;
|
||||
import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
|
||||
import com.onarandombox.MultiverseCore.localization.SimpleMessageProvider;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
||||
public class TestLocalization {
|
||||
TestInstanceCreator creator;
|
||||
Server mockServer;
|
||||
CommandSender mockCommandSender;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
creator = new TestInstanceCreator();
|
||||
assertTrue(creator.setUp());
|
||||
mockServer = creator.getServer();
|
||||
mockCommandSender = creator.getCommandSender();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
creator.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumDefaults() throws Exception {
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
assertTrue(plugin.isEnabled());
|
||||
|
||||
// Make sure Core is a MultiverseCore
|
||||
assertTrue(plugin instanceof MultiverseCore);
|
||||
|
||||
MultiverseCore core = (MultiverseCore) plugin;
|
||||
|
||||
// This should be the same core as creator.getCore()
|
||||
assertEquals(core, creator.getCore());
|
||||
|
||||
// Make sure there is neither the file nor the resource
|
||||
assertNull(core.getResource("localization/en.yml"));
|
||||
assertFalse(new File(TestInstanceCreator.pluginDirectory, "en.yml").exists());
|
||||
|
||||
// And now test it
|
||||
String actual = core.getMessageProvider().getMessage(MultiverseMessage.TEST_STRING);
|
||||
String expected = "a test-string from the enum";
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceDefaults() throws Exception {
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
assertTrue(plugin.isEnabled());
|
||||
|
||||
// Make sure Core is a MultiverseCore
|
||||
assertTrue(plugin instanceof MultiverseCore);
|
||||
|
||||
MultiverseCore core = (MultiverseCore) plugin;
|
||||
|
||||
// This should be the same core as creator.getCore()
|
||||
assertEquals(core, creator.getCore());
|
||||
|
||||
// Make sure there is no file, only the resource
|
||||
assertFalse(new File(TestInstanceCreator.pluginDirectory, "en.yml").exists());
|
||||
assertTrue(new File("src/main/resources/localization/en.yml").exists());
|
||||
doAnswer(new Answer<InputStream>() {
|
||||
@Override
|
||||
public InputStream answer(InvocationOnMock invocation) throws Throwable {
|
||||
try {
|
||||
return new FileInputStream("src/main/resources/" + (String) invocation.getArguments()[0]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}).when(core).getResource(anyString());
|
||||
assertNotNull(core.getResource("localization/en.yml"));
|
||||
|
||||
// this only works for a LazyLocaleMessageProvider
|
||||
assertTrue(core.getMessageProvider() instanceof LazyLocaleMessageProvider);
|
||||
|
||||
LazyLocaleMessageProvider messageProvider = (LazyLocaleMessageProvider) core.getMessageProvider();
|
||||
|
||||
// We have to reload it
|
||||
messageProvider.loadLocale(Locale.ENGLISH);
|
||||
|
||||
// And now test it
|
||||
String actual = core.getMessageProvider().getMessage(MultiverseMessage.TEST_STRING);
|
||||
String expected = "a test-string from the resource";
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserFile() throws Exception {
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
assertTrue(plugin.isEnabled());
|
||||
|
||||
// Make sure Core is a MultiverseCore
|
||||
assertTrue(plugin instanceof MultiverseCore);
|
||||
|
||||
MultiverseCore core = (MultiverseCore) plugin;
|
||||
|
||||
// This should be the same core as creator.getCore()
|
||||
assertEquals(core, creator.getCore());
|
||||
|
||||
// Create the file
|
||||
File file = new File(TestInstanceCreator.pluginDirectory, "en.yml");
|
||||
BufferedWriter bwriter = new BufferedWriter(new FileWriter(file));
|
||||
String expected = "a test-string from the user-file";
|
||||
bwriter.write("TEST_STRING: " + expected);
|
||||
bwriter.close();
|
||||
|
||||
// Make sure there is the file and the resource
|
||||
assertTrue(file.exists());
|
||||
assertTrue(new File("src/main/resources/localization/en.yml").exists());
|
||||
doAnswer(new Answer<InputStream>() {
|
||||
@Override
|
||||
public InputStream answer(InvocationOnMock invocation) throws Throwable {
|
||||
try {
|
||||
return new FileInputStream("src/main/resources/" + (String) invocation.getArguments()[0]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}).when(core).getResource(anyString());
|
||||
assertNotNull(core.getResource("localization/en.yml"));
|
||||
|
||||
// this only works for a LazyLocaleMessageProvider
|
||||
assertTrue(core.getMessageProvider() instanceof LazyLocaleMessageProvider);
|
||||
|
||||
LazyLocaleMessageProvider messageProvider = (LazyLocaleMessageProvider) core.getMessageProvider();
|
||||
|
||||
// We have to reload it
|
||||
messageProvider.loadLocale(Locale.ENGLISH);
|
||||
|
||||
// And now test it
|
||||
String actual = core.getMessageProvider().getMessage(MultiverseMessage.TEST_STRING);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
|
||||
// Clean up afterwards:
|
||||
assertTrue(file.delete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormat() {
|
||||
String testString = "%sthisisasimpletest&moretesting&&thatsit.";
|
||||
String result = SimpleMessageProvider.format(testString, "arg");
|
||||
assertEquals("argthisisasimpletest\u00A7moretesting&thatsit.", result);
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -1,7 +1,8 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -14,9 +15,9 @@ import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
+12
-11
@@ -5,20 +5,21 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore;
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
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.listeners.MVAsyncPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
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.configuration.file.FileConfiguration;
|
||||
@@ -167,6 +168,7 @@ public class TestWorldProperties {
|
||||
|
||||
// call player chat event
|
||||
core.getMVConfig().setPrefixChat(true);
|
||||
com.onarandombox.MultiverseCore.listeners.MVChatListener mvcl = core.getChatListener();
|
||||
((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
|
||||
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
|
||||
core.getMVConfig().setPrefixChat(false);
|
||||
@@ -298,7 +300,7 @@ public class TestWorldProperties {
|
||||
assertTrue(core.saveMVConfigs());
|
||||
// change a value here
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml"));
|
||||
WorldProperties worldObj = (WorldProperties) config.get("worlds.world");
|
||||
MVWorld worldObj = (MVWorld) config.get("worlds.world");
|
||||
assertTrue(worldObj.setColor("GREEN"));
|
||||
config.set("worlds.world", worldObj);
|
||||
config.save(new File(core.getDataFolder(), "worlds.yml"));
|
||||
@@ -331,18 +333,17 @@ public class TestWorldProperties {
|
||||
}
|
||||
|
||||
public void createEvents(MultiverseWorld mvWorld) {
|
||||
final World world = mvWorld.getCBWorld();
|
||||
//// Weather events
|
||||
// weather change
|
||||
weatherChangeOffEvent = new WeatherChangeEvent(world, false);
|
||||
weatherChangeOnEvent = new WeatherChangeEvent(world, true);
|
||||
weatherChangeOffEvent = new WeatherChangeEvent(mvWorld.getCBWorld(), false);
|
||||
weatherChangeOnEvent = new WeatherChangeEvent(mvWorld.getCBWorld(), true);
|
||||
// thunder change
|
||||
thunderChangeOffEvent = new ThunderChangeEvent(world, false);
|
||||
thunderChangeOnEvent = new ThunderChangeEvent(world, true);
|
||||
thunderChangeOffEvent = new ThunderChangeEvent(mvWorld.getCBWorld(), false);
|
||||
thunderChangeOnEvent = new ThunderChangeEvent(mvWorld.getCBWorld(), true);
|
||||
//// Player events
|
||||
// player chat
|
||||
mockPlayer = mock(Player.class);
|
||||
when(mockPlayer.getWorld()).thenReturn(world);
|
||||
when(mockPlayer.getWorld()).thenReturn(mvWorld.getCBWorld());
|
||||
when(mockPlayer.hasPlayedBefore()).thenReturn(true);
|
||||
when(mockPlayer.hasPermission("multiverse.access.world")).thenReturn(true);
|
||||
when(mockPlayer.getName()).thenReturn("MultiverseMan");
|
||||
@@ -368,7 +369,7 @@ public class TestWorldProperties {
|
||||
// entity regain health
|
||||
entityRegainHealthEvent = PowerMockito.mock(EntityRegainHealthEvent.class);
|
||||
when(entityRegainHealthEvent.getRegainReason()).thenReturn(RegainReason.REGEN);
|
||||
when(mockHumanEntity.getLocation()).thenReturn(new Location(world, 0, 0, 0));
|
||||
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);
|
||||
+10
-11
@@ -1,8 +1,10 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -16,10 +18,10 @@ import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
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 })
|
||||
@@ -111,13 +113,10 @@ public class TestWorldPurger {
|
||||
}
|
||||
|
||||
private void createAnimals() {
|
||||
World world = mvWorld.getCBWorld();
|
||||
sheep = mock(Sheep.class);
|
||||
when(sheep.getType()).thenReturn(EntityType.SHEEP);
|
||||
when(sheep.getWorld()).thenReturn(world);
|
||||
zombie = mock(Zombie.class);
|
||||
when(zombie.getType()).thenReturn(EntityType.ZOMBIE);
|
||||
when(zombie.getWorld()).thenReturn(world);
|
||||
when(cbworld.getEntities()).thenReturn(Arrays.asList((Entity) sheep, (Entity) zombie));
|
||||
}
|
||||
}
|
||||
+6
-9
@@ -5,18 +5,15 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore;
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldCreatorMatcher;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.test.utils.WorldCreatorMatcher;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@@ -197,7 +194,7 @@ public class TestWorldStuff {
|
||||
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Verify
|
||||
verify(mockCommandSender).sendMessage("Invalid generator! 'BogusGen'. " + ChatColor.RED + "Aborting world creation.");
|
||||
verify(mockCommandSender).sendMessage("Invalid generator 'BogusGen'! " + ChatColor.RED + "Aborting world creation.");
|
||||
}
|
||||
|
||||
@Test
|
||||
+2
-1
@@ -5,7 +5,7 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
@@ -21,6 +21,7 @@ import java.util.logging.LogRecord;
|
||||
public class MVTestLogFormatter extends Formatter {
|
||||
private static final DateFormat df = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
|
||||
+10
-19
@@ -5,7 +5,16 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.File;
|
||||
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;
|
||||
@@ -17,20 +26,9 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class MockWorldFactory {
|
||||
|
||||
private static final Map<String, World> createdWorlds = new HashMap<String, World>();
|
||||
private static final Map<UUID, World> worldUIDS = new HashMap<UUID, World>();
|
||||
|
||||
private static final Map<World, Boolean> pvpStates = new WeakHashMap<World, Boolean>();
|
||||
private static final Map<World, Boolean> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>();
|
||||
@@ -41,7 +39,6 @@ public class MockWorldFactory {
|
||||
|
||||
private static void registerWorld(World world) {
|
||||
createdWorlds.put(world.getName(), world);
|
||||
worldUIDS.put(world.getUID(), world);
|
||||
new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir();
|
||||
}
|
||||
|
||||
@@ -135,7 +132,6 @@ public class MockWorldFactory {
|
||||
return mockBlock;
|
||||
}
|
||||
});
|
||||
when(mockWorld.getUID()).thenReturn(UUID.randomUUID());
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
@@ -207,10 +203,6 @@ public class MockWorldFactory {
|
||||
return createdWorlds.get(name);
|
||||
}
|
||||
|
||||
public static World getWorld(UUID worldUID) {
|
||||
return worldUIDS.get(worldUID);
|
||||
}
|
||||
|
||||
public static List<World> getWorlds() {
|
||||
// we have to invert the order!
|
||||
ArrayList<World> myList = new ArrayList<World>(createdWorlds.values());
|
||||
@@ -225,6 +217,5 @@ public class MockWorldFactory {
|
||||
for (String name : createdWorlds.keySet())
|
||||
new File(TestInstanceCreator.worldsDirectory, name).delete();
|
||||
createdWorlds.clear();
|
||||
worldUIDS.clear();
|
||||
}
|
||||
}
|
||||
+10
-16
@@ -5,7 +5,7 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
@@ -13,6 +13,8 @@ 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;
|
||||
@@ -34,9 +36,10 @@ import org.powermock.core.MockGateway;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import com.onarandombox.MultiverseCore.localization.MessageProvider;
|
||||
import com.onarandombox.MultiverseCore.localization.SimpleMessageProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -76,7 +79,7 @@ public class TestInstanceCreator {
|
||||
when(pdf.getAuthors()).thenReturn(new ArrayList<String>());
|
||||
doReturn(pdf).when(core).getDescription();
|
||||
doReturn(true).when(core).isEnabled();
|
||||
doReturn(Util.logger).when(core).getLogger();
|
||||
doReturn(null).when(core).getResource(anyString());
|
||||
core.setServerFolder(serverDirectory);
|
||||
|
||||
// Add Core to the list of loaded plugins
|
||||
@@ -122,19 +125,6 @@ public class TestInstanceCreator {
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.getWorld(any(UUID.class))).thenAnswer(new Answer<World>() {
|
||||
@Override
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
UUID arg;
|
||||
try {
|
||||
arg = (UUID) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return MockWorldFactory.getWorld(arg);
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.getWorlds()).thenAnswer(new Answer<List<World>>() {
|
||||
@Override
|
||||
public List<World> answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -213,6 +203,10 @@ public class TestInstanceCreator {
|
||||
worldmanagerfield.setAccessible(true);
|
||||
worldmanagerfield.set(core, wm);
|
||||
|
||||
// Set messageProvider
|
||||
MessageProvider messageProvider = PowerMockito.spy(new SimpleMessageProvider(core));
|
||||
core.setMessageProvider(messageProvider);
|
||||
|
||||
// Set playerListener
|
||||
MVPlayerListener pl = PowerMockito.spy(new MVPlayerListener(core));
|
||||
Field playerlistenerfield = MultiverseCore.class.getDeclaredField("playerListener");
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Handler;
|
||||
+2
-1
@@ -5,7 +5,7 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
@@ -28,6 +28,7 @@ public class WorldCreatorMatcher extends ArgumentMatcher<WorldCreator> {
|
||||
this.careAboutGenerators = doICare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object creator) {
|
||||
Util.log("Checking world creators.");
|
||||
if (creator == null) {
|
||||
Reference in new issue
Block a user