2.4.0.3: Multi world choose, bug fix on /ws tp <own name>

This commit is contained in:
Butzlabben 2018-12-16 14:13:47 +01:00
parent 55da382353
commit 79bd24a75a
35 changed files with 560 additions and 202 deletions

View File

@ -5,10 +5,30 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>

View File

@ -1,7 +1,12 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/java/de/butzlabben/world/WorldSystem.java=UTF-8
encoding//src/main/java/de/butzlabben/world/command/WSCommand.java=UTF-8
encoding//src/main/java/de/butzlabben/world/config/GuiConfig.java=Cp1252
encoding//src/main/java/de/butzlabben/world/config/PluginConfig.java=Cp1252
encoding//src/main/java/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java=Cp1252
encoding//src/main/java/de/butzlabben/world/wrapper/SystemWorld.java=Cp1252
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -9,4 +9,5 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.butzlabben.world</groupId>
<artifactId>WorldSystem</artifactId>
<version>2.4.0.3-Dev</version>
<version>2.4.0.3</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.number>-</project.build.number>

View File

@ -44,7 +44,7 @@ public class AutoUpdater implements Listener {
confirmNeed = PluginConfig.confirmNeed();
UpdateInformations ui = UpdateInformations.getInformations();
if (ui == null) {
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cCouldn't contact autoupdate server");
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cCouldn't contact autoupdate server");
return;
}
Plugin plugin = Bukkit.getPluginManager().getPlugin(ui.getPlugin());
@ -83,18 +83,18 @@ public class AutoUpdater implements Listener {
Runtime.getRuntime().addShutdownHook(new Thread(au));
if (!ui.isSilent())
Bukkit.getConsoleSender().sendMessage(
PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes");
PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes");
confirmed = true;
} else {
Bukkit.getPluginManager().registerEvents(this, plugin);
for (Player p : Bukkit.getOnlinePlayers()) {
p.sendMessage(
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
p.sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
p.sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
}
Bukkit.getConsoleSender().sendMessage(
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
}
} else {
confirmNeed = false;
@ -105,8 +105,8 @@ public class AutoUpdater implements Listener {
public void on(PlayerJoinEvent e) {
if (e.getPlayer().hasPermission("ws.confirm")) {
e.getPlayer().sendMessage(
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
e.getPlayer().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
e.getPlayer().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
}
}

View File

@ -4,9 +4,13 @@ package de.butzlabben.inventory;
* @author Butzlabben
* @since 28.06.2018
*/
public class CostumInv extends OrcInventory{
public class CostumInv extends OrcInventory {
public CostumInv(String title, int rows) {
super(title, rows);
}
public CostumInv(String title, int rows, boolean fill) {
super(title, rows, fill);
}
}

View File

@ -14,6 +14,7 @@ public abstract class OrcInventory {
protected String title;
private int rows;
private InventoryType type;
private boolean fill = false;
protected HashMap<Integer, OrcItem> items = new HashMap<>();
@ -28,6 +29,16 @@ public abstract class OrcInventory {
throw new IllegalArgumentException("rows cannot be smaller than 1 or bigger than 6");
this.rows = rows;
}
public OrcInventory(String title, int rows, boolean fill) {
this(title, rows);
this.fill = fill;
if(this.fill) {
for (int i = 0; i < rows * 9; i++) {
items.put(i, OrcItem.fill);
}
}
}
public OrcInventory(String title, InventoryType type) {
this(title);

View File

@ -15,8 +15,8 @@ import de.butzlabben.world.wrapper.WorldPlayer;
public class OrcItem {
public static OrcItem enabled, disabled, coming_soon, back, error = new OrcItem(Material.BARRIER, null,
"§cERROR: Item is wrong configured!", "§cPath in config: see Displayname");
public static OrcItem enabled, disabled, coming_soon, back, fill, error = new OrcItem(Material.BARRIER, null,
"§cERROR: Item is wrong configured!", "§cPath in config: see Displayname");
private ItemStack is;
private OrcClickListener listener;

View File

@ -29,7 +29,6 @@ import de.butzlabben.world.command.WSToggleBuildCommand;
import de.butzlabben.world.command.WSToggleGMCommand;
import de.butzlabben.world.command.WSToggleTPCommand;
import de.butzlabben.world.config.DependenceConfig;
import de.butzlabben.world.config.Entry;
import de.butzlabben.world.config.GuiConfig;
import de.butzlabben.world.config.MessageConfig;
import de.butzlabben.world.config.PluginConfig;
@ -122,7 +121,7 @@ public class WorldSystem extends JavaPlugin {
System.setProperty("bstats.relocatecheck", "false");
Metrics m = new Metrics(this);
m.addCustomChart(new Metrics.SingleLineChart("worlds", Entry::entrys));
m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID));
AutoUpdater.startAsync();

View File

@ -52,7 +52,7 @@ public class WSAddmemberCommand implements CommandExecutor{
try {
wc.save();
} catch (IOException e) {
p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong");
p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong");
e.printStackTrace();
}
p.sendMessage(MessageConfig.getMemberAdded().replaceAll("%player", a.getName()));

View File

@ -16,11 +16,11 @@ public class WSConfirmCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
if (AutoUpdater.getInstance().confirmed()) {
cs.sendMessage(PluginConfig.getPrefix() + "§cAlready confirmed or no confirm needed");
cs.sendMessage(PluginConfig.getPrefix() + "§cAlready confirmed or no confirm needed");
return true;
}
AutoUpdater.getInstance().confirm();
cs.sendMessage(PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes");
cs.sendMessage(PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes");
return true;
}
}

View File

@ -59,7 +59,7 @@ public class WSDelmemberCommand implements CommandExecutor {
try {
wc.save();
} catch (IOException e) {
p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong");
p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong");
e.printStackTrace();
}
p.sendMessage(MessageConfig.getMemberRemoved().replaceAll("%player", a.getName()));

View File

@ -38,7 +38,7 @@ public class WSFireCommand implements CommandExecutor {
try {
wc.save();
} catch (IOException e) {
p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong");
p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong");
e.printStackTrace();
}
fire = wc.isFire();

View File

@ -9,14 +9,19 @@ import org.bukkit.entity.Player;
import de.butzlabben.world.WorldSystem;
import de.butzlabben.world.config.DependenceConfig;
import de.butzlabben.world.config.MessageConfig;
import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.gui.WorldChooseGUI;
import de.butzlabben.world.wrapper.SystemWorld;
import de.butzlabben.world.wrapper.WorldTemplate;
import de.butzlabben.world.wrapper.WorldTemplateProvider;
public class WSGetCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] arg3) {
public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
if (!(cs instanceof Player))
return true;
Player p = (Player) cs;
// create New Entry
DependenceConfig dc = new DependenceConfig(p);
@ -24,11 +29,34 @@ public class WSGetCommand implements CommandExecutor {
p.sendMessage(MessageConfig.getWorldAlreadyExists());
return true;
}
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
if (SystemWorld.create(p))
p.sendMessage(MessageConfig.getSettingUpWorld());
});
if (PluginConfig.isMultiChoose()) {
if (args.length >= 2) {
String key = args[1];
WorldTemplate template = WorldTemplateProvider.getInstace().getTemplate(key);
if (template != null) {
create(p, template);
return true;
}
}
p.openInventory(new WorldChooseGUI().getInventory(p));
} else {
WorldTemplate template = WorldTemplateProvider.getInstace()
.getTemplate(PluginConfig.getDefaultWorldTemplate());
if(template != null)
create(p, template);
else {
p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\"");
p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator");
}
}
return true;
}
private void create(Player p, WorldTemplate template) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
if (SystemWorld.create(p, template))
p.sendMessage(MessageConfig.getSettingUpWorld());
});
}
}

View File

@ -31,8 +31,8 @@ public class WSLeaveCommand implements CommandExecutor {
if (wp.isOnSystemWorld()) {
// Extra safety for #2
if (PluginConfig.getSpawn().getWorld() == null) {
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set");
cs.sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set");
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set");
cs.sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set");
return true;
}

View File

@ -20,7 +20,10 @@ import de.butzlabben.world.config.MessageConfig;
import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.config.WorldConfig;
import de.butzlabben.world.event.WorldResetEvent;
import de.butzlabben.world.gui.WorldChooseGUI;
import de.butzlabben.world.wrapper.SystemWorld;
import de.butzlabben.world.wrapper.WorldTemplate;
import de.butzlabben.world.wrapper.WorldTemplateProvider;
public class WSResetCommand implements CommandExecutor {
@ -61,51 +64,26 @@ public class WSResetCommand implements CommandExecutor {
}
File f = new File(PluginConfig.getWorlddir() + "/" + worldname);
File[] files = f.listFiles();
for (File file : files) {
if (file.getName().equals("worldconfig.yml"))
continue;
FileUtils.deleteQuietly(file);
}
File exampleworld = new File(
"plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName());
try {
FileUtils.copyDirectory(exampleworld, f);
toConfirm.remove(p);
FileUtils.moveDirectoryToDirectory(f, Bukkit.getWorldContainer(), false);
WorldConfig config = WorldConfig.getWorldConfig(worldname);
config.setHome(null);
config.save();
p.sendMessage(MessageConfig.getWorldReseted());
// For fast worldcreating after reset
WorldCreator creator = new WorldCreator(worldname);
long seed = PluginConfig.getSeed();
Environment env = PluginConfig.getEnvironment();
WorldType type = PluginConfig.getWorldType();
if (seed != 0)
creator.seed(seed);
creator.type(type);
creator.environment(env);
String generator = PluginConfig.getGenerator();
if (!generator.trim().isEmpty())
creator.generator(generator);
sw.setCreating(true);
// For #16
WorldSystem.getInstance().getAdapter().create(creator, sw, () -> {
if (p != null && p.isOnline())
p.sendMessage(MessageConfig.getWorldCreated());
if (!PluginConfig.isMultiChoose()) {
WorldTemplate template = WorldTemplateProvider.getInstace()
.getTemplate(PluginConfig.getDefaultWorldTemplate());
if (template != null)
createWorld(p, worldname, f, new File(template.getPath()), sw);
else {
p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\"");
p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator");
}
} else {
WorldChooseGUI.letChoose(p, (template) -> {
if (template != null)
createWorld(p, worldname, f, new File(template.getPath()), sw);
else {
p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\"");
p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator");
}
});
} catch (IOException e) {
e.printStackTrace();
p.sendMessage(MessageConfig.getUnknownError());
System.err.println("Couldn't reset world of " + p.getName());
}
} else {
p.sendMessage(MessageConfig.getInvalidInput().replaceAll("input", args[0]));
return true;
@ -132,4 +110,53 @@ public class WSResetCommand implements CommandExecutor {
}
return true;
}
private void createWorld(Player p, String worldname, File f, File exampleworld, SystemWorld sw) {
File[] files = f.listFiles();
for (File file : files) {
if (file.getName().equals("worldconfig.yml"))
continue;
FileUtils.deleteQuietly(file);
}
try {
if (exampleworld.isDirectory())
FileUtils.copyDirectory(exampleworld, f);
toConfirm.remove(p);
FileUtils.moveDirectoryToDirectory(f, Bukkit.getWorldContainer(), false);
WorldConfig config = WorldConfig.getWorldConfig(worldname);
config.setHome(null);
config.save();
p.sendMessage(MessageConfig.getWorldReseted());
// For fast worldcreating after reset
WorldCreator creator = new WorldCreator(worldname);
long seed = PluginConfig.getSeed();
Environment env = PluginConfig.getEnvironment();
WorldType type = PluginConfig.getWorldType();
if (seed != 0)
creator.seed(seed);
creator.type(type);
creator.environment(env);
String generator = PluginConfig.getGenerator();
if (!generator.trim().isEmpty())
creator.generator(generator);
sw.setCreating(true);
// For #16
WorldSystem.getInstance().getAdapter().create(creator, sw, () -> {
if (p != null && p.isOnline())
p.sendMessage(MessageConfig.getWorldCreated());
});
} catch (IOException e) {
e.printStackTrace();
p.sendMessage(MessageConfig.getUnknownError());
System.err.println("Couldn't reset world of " + p.getName());
}
}
}

View File

@ -24,10 +24,14 @@ public class WSTPCommand implements CommandExecutor {
WorldSystem.getInstance().getCommand("ws tp").getUsage()));
return true;
}
// There where some problems with /ws tp <own name>
if(args[1].equalsIgnoreCase(p.getName()) || args[1].equalsIgnoreCase(p.getUniqueId().toString())) {
p.chat("/ws home");
return true;
}
DependenceConfig dc = new DependenceConfig(args[1]);
String worldname = dc.getWorldNamebyOfflinePlayer();
if (!dc.hasWorld()) {

View File

@ -38,7 +38,7 @@ public class WSTnTCommand implements CommandExecutor {
try {
wc.save();
} catch (IOException e) {
p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong");
p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong");
e.printStackTrace();
}
tnt = wc.isTnt();

View File

@ -40,7 +40,7 @@ public class WSToggleBuildCommand implements CommandExecutor {
}
WorldPlayer wp = new WorldPlayer(a, dc.getWorldname());
if (wp.isOwnerofWorld()) {
p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner");
p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner");
return true;
}
if (wp.toggleBuild()) {

View File

@ -40,7 +40,7 @@ public class WSToggleGMCommand implements CommandExecutor {
}
WorldPlayer wp = new WorldPlayer(a, dc.getWorldname());
if (wp.isOwnerofWorld()) {
p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner");
p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner");
return true;
}
if (wp.toggleGamemode()) {

View File

@ -40,7 +40,7 @@ public class WSToggleTPCommand implements CommandExecutor {
}
WorldPlayer wp = new WorldPlayer(a, dc.getWorldname());
if (wp.isOwnerofWorld()) {
p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner");
p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner");
return true;
}
if (wp.toggleTeleport()) {

View File

@ -125,7 +125,7 @@ public class DependenceConfig {
}
}
public int getHighestID() {
public static int getHighestID() {
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig);
return dcfg.getInt("HighestID");

View File

@ -49,6 +49,7 @@ public class GuiConfig {
OrcItem.disabled = getDisabled();
OrcItem.coming_soon = getComingSoon();
OrcItem.back = getBack();
OrcItem.fill = getFill();
}
public static YamlConfiguration getConfig() {
@ -137,6 +138,14 @@ public class GuiConfig {
private static OrcItem getBack() {
return getItem("options.back");
}
private static OrcItem getFill() {
return getItem("options.fill");
}
public static boolean isFill(String path) {
return getConfig().getBoolean(path + ".fill");
}
public static Material getSkullItem() {
return getMaterial(getConfig(), "options.players.playerhead");

View File

@ -25,19 +25,19 @@ public class MessageConfig {
private static List<String> defaultCmdHelp = new ArrayList<>(20);
{
defaultCmdHelp.add("/ws get §8- §7Will give you a World");
defaultCmdHelp.add("/ws home §8- §7Teleports you on your World");
defaultCmdHelp.add("/ws sethome §8- §7Sets a specific home");
defaultCmdHelp.add("/ws tp §8- §7Teleports you on a specific World");
defaultCmdHelp.add("/ws addmember §8- §7Adds a player to your World");
defaultCmdHelp.add("/ws delmember§8 - §7Removes a player from your World");
defaultCmdHelp.add("/ws tnt §8- §7Allows/Denys TNT on your World");
defaultCmdHelp.add("/ws fire §8- §7Allows/Denys Fire on your World");
defaultCmdHelp.add("/ws togglechgm §8- §7Allows/Denys a player changing gamemode");
defaultCmdHelp.add("/ws togglebuild §8- §7Allows/Denys a player building");
defaultCmdHelp.add("/ws toggletp §8- §7Allows/Denys a player teleporting");
defaultCmdHelp.add("/ws info §8- §7Shows information about the World");
defaultCmdHelp.add("/ws reset §8- §7Will reset your World");
defaultCmdHelp.add("/ws get §8- §7Will give you a World");
defaultCmdHelp.add("/ws home §8- §7Teleports you on your World");
defaultCmdHelp.add("/ws sethome §8- §7Sets a specific home");
defaultCmdHelp.add("/ws tp §8- §7Teleports you on a specific World");
defaultCmdHelp.add("/ws addmember §8- §7Adds a player to your World");
defaultCmdHelp.add("/ws delmember§8 - §7Removes a player from your World");
defaultCmdHelp.add("/ws tnt §8- §7Allows/Denys TNT on your World");
defaultCmdHelp.add("/ws fire §8- §7Allows/Denys Fire on your World");
defaultCmdHelp.add("/ws togglechgm §8- §7Allows/Denys a player changing gamemode");
defaultCmdHelp.add("/ws togglebuild §8- §7Allows/Denys a player building");
defaultCmdHelp.add("/ws toggletp §8- §7Allows/Denys a player teleporting");
defaultCmdHelp.add("/ws info §8- §7Shows information about the World");
defaultCmdHelp.add("/ws reset §8- §7Will reset your World");
}
private static File file;
@ -78,11 +78,11 @@ public class MessageConfig {
}
public static String getNoPermission() {
return getMessage("nopermission", "§cYou don't have permissions!");
return getMessage("nopermission", "§cYou don't have permissions!");
}
public static String getSettingUpWorld() {
return getMessage("world.setting_up", "§aSetting up world...");
return getMessage("world.setting_up", "§aSetting up world...");
}
public static String getPlayerList() {
@ -90,27 +90,27 @@ public class MessageConfig {
}
public static String getLagDetection() {
return getMessage("lagdetection", "Lagdetection in world from: §c%world");
return getMessage("lagdetection", "Lagdetection in world from: §c%world");
}
public static String getWrongUsage() {
return getMessage("wrong_usage", "§c%usage");
return getMessage("wrong_usage", "§c%usage");
}
public static String getNoWorldOwn() {
return getMessage("world.does_not_exists.own", "§cYou don't have a world!");
return getMessage("world.does_not_exists.own", "§cYou don't have a world!");
}
public static String getNoWorldOther() {
return getMessage("world.does_not_exists.other", "§cThis player doesn't has a world!");
return getMessage("world.does_not_exists.other", "§cThis player doesn't has a world!");
}
public static String getNotRegistered() {
return getMessage("not_registered", "§cThis player hasn't joined yet!");
return getMessage("not_registered", "§cThis player hasn't joined yet!");
}
public static String getAlreadyMember() {
return getMessage("member.already_added", "§cThis player is already a member!");
return getMessage("member.already_added", "§cThis player is already a member!");
}
public static String getMemberAdded() {
@ -118,51 +118,51 @@ public class MessageConfig {
}
public static String getUnknownError() {
return getMessage("unknown_error", "§cSomething went wrong...");
return getMessage("unknown_error", "§cSomething went wrong...");
}
public static String getDeleteWorldOwn() {
return getMessage("world.delete.own", "§cYour world was deleted!");
return getMessage("world.delete.own", "§cYour world was deleted!");
}
public static String getDeleteWorldOther() {
return getMessage("world.delete.other", "You deleted the world of §c%player§6!");
return getMessage("world.delete.other", "You deleted the world of §c%player§6!");
}
public static String getNoMemberOwn() {
return getMessage("member.not_added.own", "§cThis player isn't a member!");
return getMessage("member.not_added.own", "§cThis player isn't a member!");
}
public static String getMemberRemoved() {
return getMessage("member.removed", "You removed §c%player§6 from your world!");
return getMessage("member.removed", "You removed §c%player§6 from your world!");
}
public static String getNoMemberAdded() {
return getMessage("member.no_one_added", "§cThere are no members added");
return getMessage("member.no_one_added", "§cThere are no members added");
}
public static String getWorldAlreadyExists() {
return getMessage("world.already_exists", "§cYou already have a world!");
return getMessage("world.already_exists", "§cYou already have a world!");
}
public static String getWorldCreated() {
return getMessage("world.created", "Your world is now ready. Get there with §a/ws home");
return getMessage("world.created", "Your world is now ready. Get there with §a/ws home");
}
public static String getWorldStillCreating() {
return getMessage("world.still_creating", "§cWorld is still creating");
return getMessage("world.still_creating", "§cWorld is still creating");
}
public static String getNotOnWorld() {
return getMessage("world.not_on", "§cYou are not on a world!");
return getMessage("world.not_on", "§cYou are not on a world!");
}
public static String getWorldStillLoaded() {
return getMessage("world.still_loaded", "§cYour world is still loaded!");
return getMessage("world.still_loaded", "§cYour world is still loaded!");
}
public static String getNoRequestSend() {
return getMessage("request.not_sent", "§cYou didn't send a request!");
return getMessage("request.not_sent", "§cYou didn't send a request!");
}
public static String getWorldReseted() {
@ -170,27 +170,27 @@ public class MessageConfig {
}
public static String getInvalidInput() {
return getMessage("request.invalid_input", "§c%input is not a valid input!");
return getMessage("request.invalid_input", "§c%input is not a valid input!");
}
public static String getRequestAlreadySent() {
return getMessage("request.already_sent", "§cYou already sent a request!");
return getMessage("request.already_sent", "§cYou already sent a request!");
}
public static String getRequestExpired() {
return getMessage("request.expired", "§cYou request is expired!");
return getMessage("request.expired", "§cYou request is expired!");
}
public static String getTimeUntilExpires() {
return getMessage("request.until_expire", "§cYour request expires in %time seconds!");
return getMessage("request.until_expire", "§cYour request expires in %time seconds!");
}
public static String getConfirmRequest() {
return getMessage("request.confirm", "§cPlease confirm reset of your world: %command");
return getMessage("request.confirm", "§cPlease confirm reset of your world: %command");
}
public static String getNoMemberOther() {
return getMessage("member.not_added.other", "§cYou are not added to this world!");
return getMessage("member.not_added.other", "§cYou are not added to this world!");
}
public static String getInfoOwner() {
@ -214,55 +214,55 @@ public class MessageConfig {
}
public static String getInfoEnabled() {
return getRawMessage("info.enabled", "§aOn");
return getRawMessage("info.enabled", "§aOn");
}
public static String getInfoDisabled() {
return getRawMessage("info.disabled", "§cOff");
return getRawMessage("info.disabled", "§cOff");
}
public static String getToggleGameModeEnabled() {
return getMessage("toggle.gamemode.enabled", "§a%player§6 can now change his gamemode!");
return getMessage("toggle.gamemode.enabled", "§a%player§6 can now change his gamemode!");
}
public static String getToggleGameModeDisabled() {
return getMessage("toggle.gamemode.disabled", "§c%player§6 can no longer change his gamemode!");
return getMessage("toggle.gamemode.disabled", "§c%player§6 can no longer change his gamemode!");
}
public static String getToggleTeleportEnabled() {
return getMessage("toggle.teleport.enabled", "§a%player§6 can now teleport!");
return getMessage("toggle.teleport.enabled", "§a%player§6 can now teleport!");
}
public static String getToggleTeleportDisabled() {
return getMessage("toggle.teleport.disabled", "§c%player§6 can no longer teleport!");
return getMessage("toggle.teleport.disabled", "§c%player§6 can no longer teleport!");
}
public static String getToggleBuildEnabled() {
return getMessage("toggle.build.enabled", "§a%player§6 can now build!");
return getMessage("toggle.build.enabled", "§a%player§6 can now build!");
}
public static String getToggleBuildDisabled() {
return getMessage("toggle.build.disabled", "§c%player§6 can no longer build!");
return getMessage("toggle.build.disabled", "§c%player§6 can no longer build!");
}
public static String getToggleFireEnabled() {
return getMessage("toggle.fire.enabled", "§aYou activated fire!");
return getMessage("toggle.fire.enabled", "§aYou activated fire!");
}
public static String getToggleFireDisabled() {
return getMessage("toggle.fire.disabled", "§cYou deactivated fire!");
return getMessage("toggle.fire.disabled", "§cYou deactivated fire!");
}
public static String getToggleTntEnabled() {
return getMessage("toggle.tnt.enabled", "§aYou activated TNT-Damage!");
return getMessage("toggle.tnt.enabled", "§aYou activated TNT-Damage!");
}
public static String getToggleTntDisabled() {
return getMessage("toggle.tnt.disabled", "§cYou deactivated TNT-Damage!");
return getMessage("toggle.tnt.disabled", "§cYou deactivated TNT-Damage!");
}
public static String getDeleteCommandHelp() {
return getMessage("command_help.delete_command", "/ws delete §8- §7Will delete a World");
return getMessage("command_help.delete_command", "/ws delete §8- §7Will delete a World");
}
public static List<String> getCommandHelp() {

View File

@ -36,12 +36,13 @@ public class PluginConfig {
file = f;
if (file.exists()) {
YamlConfiguration cfg = getConfig();
if (false == (cfg.isString("worldfolder") && cfg.isString("worldsource") && cfg.isInt("unloadingtime")
if (false == (cfg.isString("worldfolder") && cfg.isInt("unloadingtime")
&& cfg.isBoolean("survival") && cfg.isString("language") && cfg.isString("prefix")
&& cfg.isInt("request_expires") && cfg.isBoolean("need_confirm")
&& cfg.isBoolean("contact_authserver") && cfg.isBoolean("spawn_teleportation")
&& cfg.isInt("delete_after") &&
&& cfg.isBoolean("contact_authserver") && cfg.isBoolean("spawn_teleportation")
&& cfg.isInt("delete_after") && cfg.isBoolean("worldtemplates.multi_choose")
&& cfg.isString("worldtemplates.default") &&
cfg.isInt("lagsystem.period_in_seconds") && cfg.isInt("lagsystem.entities_per_world")
&& cfg.isBoolean("lagsystem.garbagecollector.use")
&& cfg.isInt("lagsystem.garbagecollector.period_in_minutes") &&
@ -91,9 +92,10 @@ public class PluginConfig {
}
}
private static YamlConfiguration getConfig() {
public static YamlConfiguration getConfig() {
try {
return YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")));
return YamlConfiguration
.loadConfiguration(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
@ -139,8 +141,12 @@ public class PluginConfig {
return getConfig().getString("worldfolder", "plugins/WorldSystem/Worlds") + "/";
}
public static String getExampleWorldName() {
return getConfig().getString("worldsource", "");
public static boolean isMultiChoose() {
return getConfig().getBoolean("worldtemplates.multi_choose", false);
}
public static String getDefaultWorldTemplate() {
return getConfig().getString("worldtemplates.default", "");
}
public static String getLanguage() {
@ -209,19 +215,19 @@ public class PluginConfig {
public static boolean contactAuth() {
return getConfig().getBoolean("contact_authserver", true);
}
public static boolean spawnTeleportation() {
return getConfig().getBoolean("spawn_teleportation", true);
}
public static boolean shouldDelete() {
return getConfig().getInt("delete_after") != -1;
}
public static long deleteAfter() {
return getConfig().getLong("delete_after");
}
public static WorldCreator getWorldCreator(String worldname) {
WorldCreator creator = new WorldCreator(worldname);
long seed = PluginConfig.getSeed();

View File

@ -21,7 +21,7 @@ public class PlayerOptionsGUI extends OrcInventory {
private final static String path = "options.player.";
public PlayerOptionsGUI(Player loader, String otherPlayer, UUID other) {
super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.player").replace("%player", otherPlayer), GuiConfig.getRows("options.player"));
super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.player").replace("%player", otherPlayer), GuiConfig.getRows("options.player"), GuiConfig.isFill("options.player"));
WorldPlayer wp = new WorldPlayer(Bukkit.getOfflinePlayer(other), loader.getWorld().getName());
loadItem("build", "/ws togglebuild " + otherPlayer, new BuildStatus(wp));
loadItem("gamemode", "/ws togglegm " + otherPlayer, new GamemodeStatus(wp));

View File

@ -0,0 +1,70 @@
package de.butzlabben.world.gui;
import java.util.function.Consumer;
import org.bukkit.entity.Player;
import de.butzlabben.inventory.OrcClickListener;
import de.butzlabben.inventory.OrcInventory;
import de.butzlabben.inventory.OrcItem;
import de.butzlabben.world.config.GuiConfig;
import de.butzlabben.world.wrapper.WorldTemplate;
import de.butzlabben.world.wrapper.WorldTemplateProvider;
/**
* @author Butzlabben
* @since 15.12.2018
*/
public class WorldChooseGUI extends OrcInventory {
private final static String path = "worldchoose.";
public WorldChooseGUI() {
this(null);
}
public WorldChooseGUI(Consumer<WorldTemplate> onClick) {
super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldchoose"), GuiConfig.getRows("worldchoose"),
GuiConfig.isFill("worldchoose"));
for (WorldTemplate template : WorldTemplateProvider.getInstace().getTemplates()) {
OrcItem icon = template.getIcon();
if(onClick != null)
icon.setOnClick((p, inv, item) -> {
p.closeInventory();
onClick.accept(template);
});
int slot = template.getSlot();
addItem(slot, icon);
}
if (GuiConfig.isEnabled(path + "back")) {
OrcItem back = OrcItem.back.clone();
back.setOnClick((p, inv, item) -> {
p.closeInventory();
});
addItem(GuiConfig.getSlot(path + "back"), back);
}
}
public static void letChoose(Player player, Consumer<WorldTemplate> template) {
player.openInventory(new WorldChooseGUI(template).getInventory(player));
}
public void loadItem(String subpath, OrcClickListener listener) {
if (GuiConfig.isEnabled(path + subpath) == false)
return;
OrcItem item = GuiConfig.getItem(path + subpath);
if (item != null) {
item.setOnClick(listener);
addItem(GuiConfig.getSlot(path + subpath), item);
}
}
public void loadItem(String subpath) {
loadItem(subpath, null);
}
public boolean canOpen(Player p) {
return true;
}
}

View File

@ -23,7 +23,7 @@ public class WorldOptionsGUI extends OrcInventory {
public final static HashMap<UUID, String> data = new HashMap<>();
public WorldOptionsGUI() {
super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.world"), GuiConfig.getRows("options.world"));
super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.world"), GuiConfig.getRows("options.world"), GuiConfig.isFill("options.world"));
loadItem("fire", "/ws fire", true, new FireStatus());
loadItem("tnt", "/ws tnt", true, new TntStatus());

View File

@ -16,7 +16,7 @@ public class WorldSystemGUI extends OrcInventory {
public WorldSystemGUI() {
super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem"));
super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem"), GuiConfig.isFill("worldsystem"));
loadItem("playeroptions", (p, inv, item) -> {
p.closeInventory();
@ -57,4 +57,4 @@ public class WorldSystemGUI extends OrcInventory {
public boolean canOpen(Player p) {
return true;
}
}
}

View File

@ -204,7 +204,7 @@ public class SystemWorld {
unloading = false;
p.sendMessage(MessageConfig.getSettingUpWorld());
// Move World into Server dir
String worlddir = PluginConfig.getWorlddir();
File world = new File(worlddir + "/" + worldname);
@ -260,11 +260,12 @@ public class SystemWorld {
* @param p Player to create the world for
* @return whether it succesfull or not
*/
public static boolean create(Player p) {
public static boolean create(Player p, WorldTemplate template) {
DependenceConfig dc = new DependenceConfig(p);
String uuid = p.getUniqueId().toString();
int id = dc.getHighestID() + 1;
int id = DependenceConfig.getHighestID() + 1;
String worldname = "ID" + id + "-" + uuid;
WorldCreator creator = PluginConfig.getWorldCreator(worldname);
@ -277,67 +278,68 @@ public class SystemWorld {
dc.createNewEntry();
String worlddir = PluginConfig.getWorlddir();
File exampleworld = new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName());
if (new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName() + "/uid.dat")
.exists()) {
new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName() + "/uid.dat").delete();
File exampleworld = new File(template.getPath());
if (new File(template.getPath() + "/uid.dat").exists()) {
new File(template.getPath() + "/uid.dat").delete();
}
File newworld = new File(worlddir + "/" + worldname);
try {
FileUtils.copyDirectory(exampleworld, newworld);
} catch (IOException e) {
System.err.println("Couldn't create world for " + p.getName());
e.printStackTrace();
}
if (exampleworld.isDirectory())
try {
FileUtils.copyDirectory(exampleworld, newworld);
} catch (IOException e) {
System.err.println("Couldn't create world for " + p.getName());
e.printStackTrace();
}
else
newworld.mkdirs();
WorldConfig.create(p);
if (PluginConfig.getExampleWorldName() == null || PluginConfig.getExampleWorldName().equals("")
|| !exampleworld.exists()) {
// Move World into Server dir
File world = new File(worlddir + "/" + worldname);
if (!world.exists()) {
world = new File(Bukkit.getWorldContainer(), worldname);
} else {
if (new File(Bukkit.getWorldContainer(), worldname).exists()
&& new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) {
try {
FileUtils.deleteDirectory(new File(Bukkit.getWorldContainer(), worldname));
} catch (IOException e) {
e.printStackTrace();
}
}
// Move World into Server dir
File world = new File(worlddir + "/" + worldname);
if (!world.exists()) {
world = new File(Bukkit.getWorldContainer(), worldname);
} else {
if (new File(Bukkit.getWorldContainer(), worldname).exists()
&& new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) {
try {
FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false);
FileUtils.deleteDirectory(new File(Bukkit.getWorldContainer(), worldname));
} catch (IOException e) {
p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage());
System.err.println("Couldn't load world of " + p.getName());
e.printStackTrace();
return false;
}
}
SystemWorld sw = SystemWorld.getSystemWorld(worldname);
sw.setCreating(true);
//Run in scheduler so method returns without delay
new BukkitRunnable() {
@Override
public void run() {
// For #16
WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> {
if (p != null && p.isOnline()) {
p.sendMessage(MessageConfig.getWorldCreated());
SettingsConfig.getCommandsonGet().stream()
.map(s -> s.replace("%player", p.getName()).replace("%world", sw.getName()).replace("%uuid",
p.getUniqueId().toString()))
.forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s));
}
});
}
}.runTaskLater(WorldSystem.getInstance(), 1);
try {
FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false);
} catch (IOException e) {
p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage());
System.err.println("Couldn't load world of " + p.getName());
e.printStackTrace();
return false;
}
}
SystemWorld sw = SystemWorld.getSystemWorld(worldname);
sw.setCreating(true);
// Run in scheduler so method returns without delay
new BukkitRunnable() {
@Override
public void run() {
// For #16
WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> {
if (p != null && p.isOnline()) {
p.sendMessage(MessageConfig.getWorldCreated());
SettingsConfig.getCommandsonGet().stream()
.map(s -> s.replace("%player", p.getName()).replace("%world", sw.getName())
.replace("%uuid", p.getUniqueId().toString()))
.forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s));
}
});
}
}.runTaskLater(WorldSystem.getInstance(), 1);
return true;
}

View File

@ -0,0 +1,42 @@
package de.butzlabben.world.wrapper;
import de.butzlabben.inventory.OrcItem;
import de.butzlabben.world.config.GuiConfig;
/**
* @author Butzlabben
* @since 15.12.2018
*/
public class WorldTemplate {
private final String name;
private final OrcItem icon;
private final int slot;
public WorldTemplate(String name) {
this.name = name;
this.icon = GuiConfig.getItem("worldchoose." + name);
this.slot = GuiConfig.getSlot("worldchoose." + name);
icon.setOnClick((p, inv, item) -> {
p.closeInventory();
p.chat("/ws get " + name);
});
}
public int getSlot() {
return slot;
}
public OrcItem getIcon() {
return icon;
}
public String getName() {
return name;
}
public String getPath() {
return "plugins/WorldSystem/worldsources/" + name;
}
}

View File

@ -0,0 +1,39 @@
package de.butzlabben.world.wrapper;
import java.util.Collection;
import java.util.HashMap;
import org.bukkit.configuration.ConfigurationSection;
import de.butzlabben.world.config.PluginConfig;
/**
* @author Butzlabben
* @since 16.12.2018
*/
public class WorldTemplateProvider {
private static WorldTemplateProvider instance = new WorldTemplateProvider();
public static WorldTemplateProvider getInstace() {
return instance;
}
private HashMap<String, WorldTemplate> templates = new HashMap<>();
private WorldTemplateProvider() {
ConfigurationSection section = PluginConfig.getConfig().getConfigurationSection("worldtemplates.templates");
for(String key: section.getKeys(false)) {
String name = section.getString(key + ".name");
templates.put(name, new WorldTemplate(name));
}
}
public WorldTemplate getTemplate(String key) {
return templates.get(key);
}
public Collection<WorldTemplate> getTemplates() {
return templates.values();
}
}

View File

@ -26,8 +26,14 @@ options:
material: BARRIER
display: '&cBack'
# When filling of an inventory is true, how the item should look like
fill:
material: GRAY_STAINED_GLASS_PANE
display: ''
# WorldoptionsGUI
world:
fill: false
# What the title of the Inv should be
title: 'World Options'
@ -122,6 +128,7 @@ options:
# PlayerGUI for managing one player on a world
player:
fill: false
title: 'Player options for %player'
back:
@ -239,6 +246,7 @@ options:
# WorldsystemGUI
worldsystem:
fill: false
title: 'WorldSystem'
rows: 1
@ -262,4 +270,37 @@ worldsystem:
row: 1
col: 9
material: GRASS_BLOCK
display: '&eWorld Options'
display: '&eWorld Options'
# GUI for choosing world template
worldchoose:
fill: false
title: 'Choose world template'
back:
enabled: true
slot:
row: 4
col: 5
rows: 4
# The key must be named exactly as in the config.yml
template_default:
enabled: true
slot:
row: 2
col: 3
material: GRASS_BLOCK
display: '&aDefault template'
another_template:
enabled: true
slot:
row: 2
col: 7
material: STONE_BLOCK
display: '&aAnother template'

View File

@ -12,8 +12,19 @@
# Path where the worlds will be saved
worldfolder: 'plugins/WorldSystem/Worlds'
# Name of the template world
worldsource: ''
worldtemplates:
# Wheter players can decide on different templates
multi_choose: false
# If multi_choose is disabled, which template should be choosen
default: 'template_default'
templates:
# The "1" can be any key
1:
# Name of directory in plugins/WorldSystem/worldsources
# e.g. this would be plugins/WorldSystem/worldsources/template_default
name: 'template_default'
2:
name: 'another_template'
# If a confirm is needed before auto-update
need_confirm: true

View File

@ -30,8 +30,15 @@ options:
material: BARRIER
display: '&cBack'
# When filling of an inventory is true, how the item should look like
fill:
material: STAINED_GLASS_PANE
data: 7
display: ''
# WorldoptionsGUI
world:
fill: false
# What the title of the Inv should be
title: 'World Options'
@ -120,6 +127,7 @@ options:
# PlayerGUI for managing one player on a world
player:
fill: false
title: 'Player options for %player'
back:
@ -237,6 +245,7 @@ options:
# WorldsystemGUI
worldsystem:
fill: false
title: 'WorldSystem'
rows: 1
@ -260,4 +269,34 @@ worldsystem:
row: 1
col: 9
material: GRASS
display: '&eWorld Options'
display: '&eWorld Options'
# GUI for choosing world template
worldchoose:
fill: false
title: 'Choose world template'
back:
enabled: true
slot:
row: 4
col: 5
rows: 4
# The key must be named exactly as in the config.yml
template_default:
enabled: true
slot:
row: 2
col: 3
material: GRASS
display: '&aDefault template'
another_template:
enabled: true
slot:
row: 2
col: 7
material: STONE
display: '&aAnother template'