mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Recoded chat system; resolves #207
This commit is contained in:
parent
b3eac538d5
commit
c506405a01
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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()) {
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user