Skip to content

Commit

Permalink
Make <player.chat_history> tags have a config.yml option
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed May 25, 2015
1 parent b86ce43 commit 50105c0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -240,7 +240,7 @@


public class Denizen extends JavaPlugin implements DenizenImplementation {
public final static int configVersion = 10;
public final static int configVersion = 11;
public static String versionTag = null;
private boolean startedSuccessful = false;

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/net/aufdemrand/denizen/Settings.java
Expand Up @@ -216,12 +216,12 @@ public static boolean allowRunningJava() {

public static boolean allowLogging() {
return DenizenAPI.getCurrentInstance().getConfig()
.getBoolean("Commands.log.Allow logging", true);
.getBoolean("Commands.Log.Allow logging", true);
}

public static boolean allowStrangeYAMLSaves() {
return DenizenAPI.getCurrentInstance().getConfig()
.getBoolean("Commands.yaml.Allow saving outside folder", false);
.getBoolean("Commands.Yaml.Allow saving outside folder", false);
}

public static String chatMultipleTargetsFormat() {
Expand Down Expand Up @@ -372,4 +372,9 @@ public static int pathfindingMaxDistance() {
return DenizenAPI.getCurrentInstance().getConfig()
.getInt("Tags.Path finding.Max distance", 100);
}

public static int chatHistoryMaxMessages() {
return DenizenAPI.getCurrentInstance().getConfig()
.getInt("Tags.Chat history.Max messages", 10);
}
}
33 changes: 18 additions & 15 deletions src/main/java/net/aufdemrand/denizen/tags/core/PlayerTags.java
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.tags.core;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizencore.tags.ReplaceableTagEvent;
import net.aufdemrand.denizencore.tags.Attribute;
Expand Down Expand Up @@ -34,21 +35,23 @@ public PlayerTags(Denizen denizen) {

@EventHandler(priority = EventPriority.MONITOR)
public void addMessage(final AsyncPlayerChatEvent event) {
Bukkit.getScheduler().runTaskLater(DenizenAPI.getCurrentInstance(), new Runnable() {
@Override
public void run() {
List<String> history = playerChatHistory.get(event.getPlayer().getName());
// If history hasn't been started for this player, initialize a new ArrayList
if (history == null) history = new ArrayList<String>();
// Maximum history size is 10
// TODO: Make size configurable
if (history.size() > 10) history.remove(9);
// Add message to history
history.add(0, event.getMessage());
// Store the new history
playerChatHistory.put(event.getPlayer().getName(), history);
}
}, 1);
final int maxSize = Settings.chatHistoryMaxMessages();
if (maxSize > 0) {
Bukkit.getScheduler().runTaskLater(DenizenAPI.getCurrentInstance(), new Runnable() {
@Override
public void run() {
List<String> history = playerChatHistory.get(event.getPlayer().getName());
// If history hasn't been started for this player, initialize a new ArrayList
if (history == null) history = new ArrayList<String>();
// Maximum history size is specified by config.yml
if (history.size() > maxSize) history.remove(maxSize - 1);
// Add message to history
history.add(0, event.getMessage());
// Store the new history
playerChatHistory.put(event.getPlayer().getName(), history);
}
}, 1);
}
}


Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/config.yml
Expand Up @@ -93,11 +93,11 @@ Commands:
# This is extremely dangerous and should be kept off unless monitored carefully.
# Set to 'false' if you're worried about security.
Allow running java: false
log:
Log:
# The log command writes to file, which is potentially dangerous
# Set to 'false' if you're worried about security.
Allow logging: true
yaml:
Yaml:
# Whether the YAML command is allowed to save outside the minecraft folder.
# Set to 'false' if you're worried about security.
Allow saving outside folder: false
Expand All @@ -113,9 +113,11 @@ Tags:
Path finding:
# How far away the path finder can search before giving up
Max distance: 100

Chat history:
# How many player messages will be stored for each player (<player.chat_history>, etc.)
Max messages: 10

# The version of this configuration file, used to check if your
# configuration file is outdated or too new
Config:
Version: 10
Version: 11

0 comments on commit 50105c0

Please sign in to comment.