Readd DXL chat in edit mode; resolves #457

This commit is contained in:
Daniel Saukel 2018-08-13 20:00:14 +02:00
parent 109dfd72c9
commit fef6a1f39d
12 changed files with 84 additions and 39 deletions

View File

@ -80,7 +80,7 @@ public class Announcer {
}
/**
* @param name the name of the Announcer
* @param name the name of the Announcer
* @param config the config that stores the information
*/
public Announcer(String name, FileConfiguration config) {
@ -112,12 +112,12 @@ public class Announcer {
}
/**
* @param name the name of the Announcer
* @param description the description messages
* @param worlds the names of the worlds where the announcement will be seen or null to broadcast it to all worlds
* @param identifier the dungeon identifier
* @param multiFloor if the identifier refers to an MFD (true) or an SFD (false)
* @param maxGroupsPerGame the amount of groups in one game
* @param name the name of the Announcer
* @param description the description messages
* @param worlds the names of the worlds where the announcement will be seen or null to broadcast it to all worlds
* @param identifier the dungeon identifier
* @param multiFloor if the identifier refers to an MFD (true) or an SFD (false)
* @param maxGroupsPerGame the amount of groups in one game
* @param maxPlayersPerGroup the amount of players in one group
*/
public Announcer(String name, List<String> description, List<String> worlds, String identifier, boolean multiFloor, short maxGroupsPerGame, int maxPlayersPerGroup) {

View File

@ -20,6 +20,7 @@ import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.command.DRECommand;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DEditPlayer;
import de.erethon.dungeonsxl.player.DGlobalPlayer;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.player.DPermission;
@ -45,7 +46,7 @@ public class ChatCommand extends DRECommand {
Player player = (Player) sender;
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player);
if (DGroup.getByPlayer(player) == null) {
if (DGroup.getByPlayer(player) == null && !(dPlayer instanceof DEditPlayer)) {
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
return;
}

View File

@ -28,7 +28,6 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
/**
* @author Frank Baumann, Daniel Saukel

View File

@ -16,8 +16,6 @@
*/
package de.erethon.dungeonsxl.config;
import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.compatibility.Internals;
import de.erethon.commons.config.DREConfig;
import de.erethon.commons.misc.EnumUtil;
import de.erethon.dungeonsxl.DungeonsXL;
@ -48,13 +46,14 @@ public class MainConfig extends DREConfig {
NEVER
}
public static final int CONFIG_VERSION = 15;
public static final int CONFIG_VERSION = 16;
private String language = "english";
private boolean enableEconomy = false;
/* Chat */
private boolean chatEnabled = true;
private String chatFormatEdit = "&2[Edit] &r%player_name%: ";
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";
@ -160,6 +159,20 @@ public class MainConfig extends DREConfig {
chatEnabled = enabled;
}
/**
* @return the edit chat format
*/
public String getChatFormatEdit() {
return chatFormatEdit;
}
/**
* @param string the edit chat format to set
*/
public void setEditFormatEdit(String string) {
chatFormatEdit = string;
}
/**
* @return the game chat format
*/
@ -451,16 +464,20 @@ public class MainConfig extends DREConfig {
config.set("chatEnabled", chatEnabled);
}
if (!config.contains("chatFormatGame")) {
config.set("chatFormatGame", chatFormatGame);
if (!config.contains("chatFormat.edit")) {
config.set("chatFormat.edit", chatFormatEdit);
}
if (!config.contains("chatFormatGroup")) {
config.set("chatFormatGroup", chatFormatGroup);
if (!config.contains("chatFormat.game")) {
config.set("chatFormat.game", chatFormatGame);
}
if (!config.contains("chatFormatSpy")) {
config.set("chatFormatSpy", chatFormatSpy);
if (!config.contains("chatFormat.group")) {
config.set("chatFormat.group", chatFormatGroup);
}
if (!config.contains("chatFormat.spy")) {
config.set("chatFormat.spy", chatFormatSpy);
}
if (!config.contains("tutorial.activated")) {
@ -562,16 +579,20 @@ public class MainConfig extends DREConfig {
chatEnabled = config.getBoolean("chatEnabled");
}
if (config.contains("chatFormatGame")) {
chatFormatGame = config.getString("chatFormatGame");
if (config.contains("chatFormat.edit")) {
chatFormatEdit = config.getString("chatFormat.edit");
}
if (config.contains("chatFormatGroup")) {
chatFormatGroup = config.getString("chatFormatGroup");
if (config.contains("chatFormat.game")) {
chatFormatGame = config.getString("chatFormat.game");
}
if (config.contains("chatFormatSpy")) {
chatFormatSpy = config.getString("chatFormatSpy");
if (config.contains("chatFormat.group")) {
chatFormatGroup = config.getString("chatFormat.group");
}
if (config.contains("chatFormat.spy")) {
chatFormatSpy = config.getString("chatFormat.spy");
}
if (config.contains("chatEnabled")) {

View File

@ -77,7 +77,7 @@ public class DMobType extends ExMob {
}
/**
* @param name the name of the DMobType
* @param name the name of the DMobType
* @param config the config that stores the information
*/
public DMobType(String name, FileConfiguration config) {

View File

@ -36,17 +36,17 @@ public interface ExternalMobProvider {
public String getRawCommand();
/**
* @param mob the mob identifier
* @param mob the mob identifier
* @param world the game world
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @return the command with replaced variables
*/
public String getCommand(String mob, String world, double x, double y, double z);
/**
* @param mob the mob identifier
* @param mob the mob identifier
* @param location the location where the mob will be spawned
*/
public void summon(String mob, Location location);

View File

@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.player;
import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.util.ParsingUtil;
import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.DInstanceWorld;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -101,7 +102,8 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
if (instance == null) {
return;
}
instance.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatGame(), this) + message);
String chatFormat = instance instanceof DGameWorld ? config.getChatFormatGame() : config.getChatFormatEdit();
instance.sendMessage(ParsingUtil.replaceChatPlaceholders(chatFormat, this) + message);
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) {
if (player.isInChatSpyMode()) {

View File

@ -18,7 +18,9 @@ package de.erethon.dungeonsxl.player;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.world.DInstanceWorld;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
@ -78,6 +80,16 @@ public class DPlayerCache {
return null;
}
/**
* @param instance the instance to check
* @return a Collection of DInstancePlayers in this instance
*/
public Collection<DInstancePlayer> getByInstance(DInstanceWorld instance) {
Collection<DInstancePlayer> players = new ArrayList<>();
plugin.getDWorlds().getInstances().forEach(i -> i.getPlayers().forEach(p -> players.add(p)));
return players;
}
/**
* @return the dGlobalPlayers
*/

View File

@ -53,7 +53,6 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
@ -232,6 +231,13 @@ public class DPlayerListener implements Listener {
if (!dPlayer.isInGroupChat()) {
return;
}
if (dPlayer instanceof DEditPlayer) {
event.setCancelled(true);
((DInstancePlayer) dPlayer).chat(event.getMessage());
return;
}
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
return;

View File

@ -42,7 +42,7 @@ public class SignScript {
}
/**
* @param name the name of the Announcer
* @param name the name of the Announcer
* @param config the config that stores the information
*/
public SignScript(String name, FileConfiguration config) {

View File

@ -56,11 +56,14 @@ public enum ParsingUtil {
* @return the string with the placeholders replaced
*/
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());
DGroup group = DGroup.getByPlayer(sender.getPlayer());
if (group != null) {
string = string.replaceAll(GROUP_COLOR.getPlaceholder(), group.getDColor().getChatColor().toString());
string = string.replaceAll(GROUP_NAME.getPlaceholder(), group.getName());
}
return string;
}

View File

@ -20,8 +20,8 @@ import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.player.PlayerUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.game.GameRuleProvider;
import de.erethon.dungeonsxl.player.DGamePlayer;
import de.erethon.dungeonsxl.player.DInstancePlayer;
import de.erethon.dungeonsxl.player.DPlayerCache;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
@ -38,6 +38,7 @@ public abstract class DInstanceWorld {
DungeonsXL plugin = DungeonsXL.getInstance();
DWorldCache worlds = plugin.getDWorlds();
DPlayerCache dPlayers = plugin.getDPlayers();
private DResourceWorld resourceWorld;
private File folder;
@ -138,7 +139,7 @@ public abstract class DInstanceWorld {
* @param message the message to send
*/
public void sendMessage(String message) {
for (DGamePlayer dPlayer : DGamePlayer.getByWorld(world)) {
for (DInstancePlayer dPlayer : dPlayers.getByInstance(this)) {
MessageUtil.sendMessage(dPlayer.getPlayer(), message);
}
}