From c506405a01877e8554f372a587e4dadf87b1ca67 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Feb 2017 18:05:03 +0100 Subject: [PATCH] Recoded chat system; resolves #207 --- .../dre2n/dungeonsxl/command/ChatCommand.java | 17 +-- .../dungeonsxl/command/ChatSpyCommand.java | 14 +-- .../dre2n/dungeonsxl/command/DCommands.java | 7 +- .../dre2n/dungeonsxl/config/MainConfig.java | 108 +++++++++++++++++- .../dre2n/dungeonsxl/player/DEditPlayer.java | 15 --- .../dre2n/dungeonsxl/player/DGamePlayer.java | 15 --- .../dungeonsxl/player/DGlobalPlayer.java | 36 +++++- .../dungeonsxl/player/DInstancePlayer.java | 48 ++++---- .../dungeonsxl/player/DPlayerListener.java | 31 +++-- .../dre2n/dungeonsxl/util/ParsingUtil.java | 68 +++++++++++ .../dungeonsxl/world/DResourceWorld.java | 7 +- .../dre2n/dungeonsxl/world/DWorlds.java | 18 ++- 12 files changed, 293 insertions(+), 91 deletions(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/util/ParsingUtil.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ChatCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ChatCommand.java index 533c4893..2de25d41 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ChatCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ChatCommand.java @@ -20,7 +20,8 @@ import io.github.dre2n.commons.command.BRCommand; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; -import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPermissions; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -42,21 +43,15 @@ public class ChatCommand extends BRCommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + DGlobalPlayer dPlayer = DungeonsXL.getDPlayers().getByPlayer(player); - if (dPlayer == null) { + if (DGroup.getByPlayer(player) == null) { MessageUtil.sendMessage(player, DMessages.ERROR_JOIN_GROUP.getMessage()); return; } - if (dPlayer.isInDungeonChat()) { - dPlayer.setInDungeonChat(false); - MessageUtil.sendMessage(player, DMessages.CMD_CHAT_NORMAL_CHAT.getMessage()); - - } else { - dPlayer.setInDungeonChat(true); - MessageUtil.sendMessage(player, DMessages.CMD_CHAT_DUNGEON_CHAT.getMessage()); - } + dPlayer.setInGroupChat(!dPlayer.isInGroupChat()); + MessageUtil.sendMessage(player, (dPlayer.isInGroupChat() ? DMessages.CMD_CHAT_DUNGEON_CHAT : DMessages.CMD_CHAT_NORMAL_CHAT).getMessage()); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ChatSpyCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ChatSpyCommand.java index 5bbe0d59..69f5f96e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ChatSpyCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ChatSpyCommand.java @@ -31,7 +31,7 @@ import org.bukkit.entity.Player; public class ChatSpyCommand extends BRCommand { public ChatSpyCommand() { - setCommand("chatspy"); + setCommand("chatSpy"); setMinArgs(0); setMaxArgs(0); setHelp(DMessages.HELP_CMD_CHATSPY.getMessage()); @@ -42,16 +42,10 @@ public class ChatSpyCommand extends BRCommand { @Override public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - DGlobalPlayer dGlobalPlayer = DungeonsXL.getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = DungeonsXL.getDPlayers().getByPlayer(player); - if (dGlobalPlayer.isInChatSpyMode()) { - dGlobalPlayer.setInChatSpyMode(false); - MessageUtil.sendMessage(player, DMessages.CMD_CHATSPY_STOPPED.getMessage()); - - } else { - dGlobalPlayer.setInChatSpyMode(true); - MessageUtil.sendMessage(player, DMessages.CMD_CHATSPY_START.getMessage()); - } + dPlayer.setInChatSpyMode(!dPlayer.isInChatSpyMode()); + MessageUtil.sendMessage(player, (dPlayer.isInChatSpyMode() ? DMessages.CMD_CHATSPY_START : DMessages.CMD_CHATSPY_STOPPED).getMessage()); } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java index 537c097b..25b2a466 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java @@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.command; import io.github.dre2n.commons.command.BRCommands; import io.github.dre2n.commons.javaplugin.BRPlugin; +import io.github.dre2n.dungeonsxl.DungeonsXL; /** * An enumeration of all command instances. @@ -60,8 +61,6 @@ public class DCommands extends BRCommands { public DCommands(BRPlugin plugin) { super("dungeonsxl", plugin, BREAK, - CHAT, - CHAT_SPY, CREATE, DELETE, EDIT, @@ -91,6 +90,10 @@ public class DCommands extends BRCommands { UNINVITE, new DeletePortalCommand() ); + if (DungeonsXL.getMainConfig().isChatEnabled()) { + addCommand(CHAT); + addCommand(CHAT_SPY); + } } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index 55438b76..88494196 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -47,11 +47,17 @@ public class MainConfig extends BRConfig { NEVER } - public static final int CONFIG_VERSION = 13; + public static final int CONFIG_VERSION = 14; private String language = "english"; private boolean enableEconomy = false; + /* Chat */ + private boolean chatEnabled = true; + private String chatFormatGame = "&2[Game] %group_color%%player_name%: &r"; + private String chatFormatGroup = "&2%group_color%[%group_name%] %player_name%: &r"; + private String chatFormatSpy = "&2[Chat Spy] %player_name%: &r"; + /* Tutorial */ private boolean tutorialActivated = false; private String tutorialDungeon = "tutorial"; @@ -140,6 +146,70 @@ public class MainConfig extends BRConfig { enableEconomy = enabled; } + /** + * @return + * if the dungeon chat is enabled + */ + public boolean isChatEnabled() { + return chatEnabled; + } + + /** + * @param enabled + * if the dungeon chat is enabled + */ + public void setChatEnabled(boolean enabled) { + chatEnabled = enabled; + } + + /** + * @return + * the game chat format + */ + public String getChatFormatGame() { + return chatFormatGame; + } + + /** + * @param string + * the game chat format to set + */ + public void setChatFormatGame(String string) { + chatFormatGame = string; + } + + /** + * @return + * the group chat format + */ + public String getChatFormatGroup() { + return chatFormatGroup; + } + + /** + * @param string + * the group chat format to set + */ + public void setChatFormatGroup(String string) { + chatFormatGroup = string; + } + + /** + * @return + * the chat spy format + */ + public String getChatFormatSpy() { + return chatFormatSpy; + } + + /** + * @param string + * the chat spy format to set + */ + public void setChatFormatSpy(String string) { + chatFormatSpy = string; + } + /** * @return if the tutorial is activated */ @@ -396,6 +466,22 @@ public class MainConfig extends BRConfig { config.set("enableEconomy", enableEconomy); } + if (!config.contains("chatEnabled")) { + config.set("chatEnabled", chatEnabled); + } + + if (!config.contains("chatFormatGame")) { + config.set("chatFormatGame", chatFormatGame); + } + + if (!config.contains("chatFormatGroup")) { + config.set("chatFormatGroup", chatFormatGroup); + } + + if (!config.contains("chatFormatSpy")) { + config.set("chatFormatSpy", chatFormatSpy); + } + if (!config.contains("tutorial.activated")) { config.set("tutorial.activated", tutorialActivated); } @@ -491,6 +577,26 @@ public class MainConfig extends BRConfig { enableEconomy = config.getBoolean("enableEconomy"); } + if (config.contains("chatEnabled")) { + chatEnabled = config.getBoolean("chatEnabled"); + } + + if (config.contains("chatFormatGame")) { + chatFormatGame = config.getString("chatFormatGame"); + } + + if (config.contains("chatFormatGroup")) { + chatFormatGroup = config.getString("chatFormatGroup"); + } + + if (config.contains("chatFormatSpy")) { + chatFormatSpy = config.getString("chatFormatSpy"); + } + + if (config.contains("chatEnabled")) { + chatEnabled = config.getBoolean("chatEnabled"); + } + if (config.contains("tutorial.activated")) { tutorialActivated = config.getBoolean("tutorial.activated"); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java index be3a840b..67874588 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java @@ -24,7 +24,6 @@ import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEv import io.github.dre2n.dungeonsxl.world.DEditWorld; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; @@ -168,20 +167,6 @@ public class DEditPlayer extends DInstancePlayer { } } - @Override - public void sendMessage(String message) { - DEditWorld editWorld = DEditWorld.getByWorld(getWorld()); - editWorld.sendMessage(message); - - for (DGlobalPlayer player : DungeonsXL.getDPlayers().getDGlobalPlayers()) { - if (player.isInChatSpyMode()) { - if (!editWorld.getWorld().getPlayers().contains(player.getPlayer())) { - MessageUtil.sendMessage(player.getPlayer(), ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message); - } - } - } - } - @Override public void update(boolean updateSecond) { boolean locationValid = true; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 20465fe5..e8e05d7c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -41,7 +41,6 @@ import java.io.File; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -800,20 +799,6 @@ public class DGamePlayer extends DInstancePlayer { } } - @Override - public void sendMessage(String message) { - DGameWorld gameWorld = DGameWorld.getByWorld(getWorld()); - gameWorld.sendMessage(message); - - for (DGlobalPlayer player : DungeonsXL.getDPlayers().getDGlobalPlayers()) { - if (player.isInChatSpyMode()) { - if (!gameWorld.getWorld().getPlayers().contains(player.getPlayer())) { - MessageUtil.sendMessage(player.getPlayer(), ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message); - } - } - } - } - public void onDeath(PlayerDeathEvent event) { DGameWorld gameWorld = DGameWorld.getByWorld(player.getLocation().getWorld()); if (gameWorld == null) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index 3721817d..d0a7c28a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -47,8 +47,9 @@ public class DGlobalPlayer { private DPlayerData data; - private boolean breakMode; - private boolean chatSpyMode; + private boolean breakMode = false; + private boolean groupChat = false; + private boolean chatSpyMode = false; private DPortal creatingPortal; private boolean announcerEnabled = true; @@ -127,10 +128,31 @@ public class DGlobalPlayer { this.breakMode = breakMode; } + /** + * @return if the player is in group chat + */ + public boolean isInGroupChat() { + if (!DungeonsXL.getMainConfig().isChatEnabled()) { + return false; + } + return groupChat; + } + + /** + * @param groupChat + * set if the player is in group chat + */ + public void setInGroupChat(boolean groupChat) { + this.groupChat = groupChat; + } + /** * @return if the player spies the DXL chat channels */ public boolean isInChatSpyMode() { + if (!DungeonsXL.getMainConfig().isChatEnabled()) { + return false; + } return chatSpyMode; } @@ -264,6 +286,16 @@ public class DGlobalPlayer { } /* Actions */ + /** + * Sends a message to the player + * + * @param message + * the message to send + */ + public void sendMessage(String message) { + MessageUtil.sendMessage(player, message); + } + /** * Respawns the player at his old position before he was in a dungeon */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java index 46d97c1b..9a1f60be 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java @@ -17,6 +17,9 @@ package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.MainConfig; +import io.github.dre2n.dungeonsxl.util.ParsingUtil; +import io.github.dre2n.dungeonsxl.world.DInstanceWorld; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; @@ -28,8 +31,9 @@ import org.bukkit.potion.PotionEffect; */ public abstract class DInstancePlayer extends DGlobalPlayer { + MainConfig config = DungeonsXL.getMainConfig(); + private World world; - private boolean inDungeonChat = false; DInstancePlayer(Player player, World world) { super(player, false); @@ -54,21 +58,6 @@ public abstract class DInstancePlayer extends DGlobalPlayer { world = instance; } - /** - * @return the inDungeonChat - */ - public boolean isInDungeonChat() { - return inDungeonChat; - } - - /** - * @param inDungeonChat - * the inDungeonChat to set - */ - public void setInDungeonChat(boolean inDungeonChat) { - this.inDungeonChat = inDungeonChat; - } - // Players in dungeons never get announcer messages @Override public boolean isAnnouncerEnabled() { @@ -105,17 +94,34 @@ public abstract class DInstancePlayer extends DGlobalPlayer { } } + /** + * Makes the player send a message to the world. + * + * @param message + * the message to send + */ + public void chat(String message) { + DInstanceWorld instance = DungeonsXL.getDWorlds().getInstanceByWorld(world); + if (instance == null) { + return; + } + instance.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatGame(), this) + message); + + for (DGlobalPlayer player : DungeonsXL.getDPlayers().getDGlobalPlayers()) { + if (player.isInChatSpyMode()) { + if (!instance.getWorld().getPlayers().contains(player.getPlayer())) { + player.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatSpy(), this) + message); + } + } + } + } + /* Abstracts */ /** * The player leaves the dungeon and / or his group. */ public abstract void leave(); - /** - * Sends a message to the player and the world. - */ - public abstract void sendMessage(String message); - /** * Repeating checks for the player. * diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java index 2ab43231..6cb2b7cd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java @@ -25,6 +25,7 @@ import io.github.dre2n.dungeonsxl.global.DPortal; import io.github.dre2n.dungeonsxl.global.GlobalProtection; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger; +import io.github.dre2n.dungeonsxl.util.ParsingUtil; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.block.LockedDoor; @@ -65,6 +66,9 @@ public class DPlayerListener implements Listener { DungeonsXL plugin; DPlayers dPlayers; + MainConfig config = DungeonsXL.getMainConfig(); + + public static final String ALL = "@all "; public DPlayerListener(DPlayers dPlayers) { this.plugin = DungeonsXL.getInstance(); @@ -216,14 +220,24 @@ public class DPlayerListener implements Listener { if (isCitizensNPC(player)) { return; } - DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); + DGlobalPlayer dPlayer = dPlayers.getByPlayer(player); if (dPlayer == null) { return; } + if (!dPlayer.isInGroupChat()) { + return; + } + DGroup dGroup = DGroup.getByPlayer(player); + if (dGroup == null) { + return; + } - if (dPlayer.isInDungeonChat()) { - dPlayer.sendMessage(player.getDisplayName() + ": " + event.getMessage()); - event.setCancelled(true); + boolean game = event.getMessage().startsWith(ALL) && dPlayer instanceof DInstancePlayer; + event.setCancelled(true); + if (game) { + ((DInstancePlayer) dPlayer).chat(event.getMessage().substring(ALL.length())); + } else { + dGroup.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatGroup(), dPlayer) + event.getMessage()); } } @@ -253,7 +267,7 @@ public class DPlayerListener implements Listener { return; } else { - commandWhitelist.addAll(DungeonsXL.getMainConfig().getEditCommandWhitelist()); + commandWhitelist.addAll(config.getEditCommandWhitelist()); } } else if (game != null) { @@ -304,7 +318,7 @@ public class DPlayerListener implements Listener { return; } - if (dPlayer instanceof DEditPlayer && !DungeonsXL.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) { + if (dPlayer instanceof DEditPlayer && !config.getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) { event.setCancelled(true); } @@ -352,7 +366,7 @@ public class DPlayerListener implements Listener { return; } - if (!DungeonsXL.getMainConfig().isTutorialActivated()) { + if (!config.isTutorialActivated()) { return; } @@ -581,7 +595,8 @@ public class DPlayerListener implements Listener { if (dGlobalPlayer.isCreatingPortal()) { if (item.getType() == Material.WOOD_SWORD) { if (clickedBlock != null) { - for (GlobalProtection protection : DungeonsXL.getGlobalProtections().getProtections(DPortal.class)) { + for (GlobalProtection protection : DungeonsXL.getGlobalProtections().getProtections(DPortal.class + )) { DPortal dPortal = (DPortal) protection; if (!dPortal.isActive()) { if (dPortal == dGlobalPlayer.getPortal()) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/util/ParsingUtil.java b/core/src/main/java/io/github/dre2n/dungeonsxl/util/ParsingUtil.java new file mode 100644 index 00000000..06b17a77 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/util/ParsingUtil.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2012-2017 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.util; + +import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; + +/** + * @author Daniel Saukel + */ +public enum ParsingUtil { + + GROUP_COLOR("%group_color%"), + GROUP_NAME("%group_name%"), + PLAYER_NAME("%player_name%"); + + private String placeholder; + + ParsingUtil(String placeholder) { + this.placeholder = placeholder; + } + + /* Getters and setters */ + /** + * @return the placeholder + */ + public String getPlaceholder() { + return placeholder; + } + + @Override + public String toString() { + return placeholder; + } + + /* Statics */ + /** + * Replace the placeholders that are relevant for the chat in a String automatically. + * + * @param string + * the String that contains the placeholders + * @param sender + * the DGlobalPlayer who sent the message + */ + public static String replaceChatPlaceholders(String string, DGlobalPlayer sender) { + DGroup group = DGroup.getByPlayer(sender.getPlayer()); + + string = string.replaceAll(PLAYER_NAME.getPlaceholder(), sender.getName()); + string = string.replaceAll(GROUP_COLOR.getPlaceholder(), group.getDColor().getChatColor().toString()); + string = string.replaceAll(GROUP_NAME.getPlaceholder(), group.getName()); + return string; + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java index 0b4d98eb..be669d53 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java @@ -203,11 +203,12 @@ public class DResourceWorld { */ public DInstanceWorld instantiate(final boolean game) { int id = worlds.generateId(); - String name = worlds.generateName(game); + String name = worlds.generateName(game, id); final File instanceFolder = new File(Bukkit.getWorldContainer(), name); - if (Bukkit.getWorld(name) != null) { - return null; + while (Bukkit.getWorld(name) != null) { + id++; + name = worlds.generateName(game, id); } final DInstanceWorld instance = game ? new DGameWorld(this, instanceFolder, id) : new DEditWorld(this, instanceFolder, id); diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java index 7baf8248..faee8c18 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java @@ -263,13 +263,25 @@ public class DWorlds { } /** - * @return a name for the instance - * + * @return + * a name for the instance * @param game * whether the instance is a DGameWorld */ public String generateName(boolean game) { - return "DXL_" + (game ? "Game" : "Edit") + "_" + generateId(); + return generateName(game, generateId()); + } + + /** + * @return + * a name for the instance + * @param game + * whether the instance is a DGameWorld + * @param id + * the id to use + */ + public String generateName(boolean game, int id) { + return "DXL_" + (game ? "Game" : "Edit") + "_" + id; } /**