Compare commits

..
38 Commits
Author SHA1 Message Date
dadus33 769dfc3f8e Add placeholder count limit. Remove command system. 2016-10-29 14:02:05 +03:00
LongLiveVladerius@gmail.com 8c061a057c Merge remote-tracking branch 'origin/master' 2016-10-24 21:21:57 +03:00
dadus33 e41a8e3db5 Fixed NPE in ChatPacketListener. 2016-10-24 21:21:53 +03:00
dadus33 1fc0538ff4 Fixed NPE in ChatPacketListener. 2016-10-24 21:21:21 +03:00
dadus33 fff868cf25 Changed version string. 2016-10-23 16:37:15 +03:00
LongLiveVladerius@gmail.com 51b91b3c3d Merge remote-tracking branch 'origin/master' 2016-10-23 16:36:08 +03:00
LongLiveVladerius@gmail.com a20ed832f4 Fixed error when using item names with dollar sign or backslash. 2016-10-23 16:36:02 +03:00
dadus33 4ebbdc1c64 Updated README.MD 2016-10-19 18:26:24 +03:00
LongLiveVladerius@gmail.com f0eb998f23 Merge remote-tracking branch 'origin/master' 2016-10-19 18:19:56 +03:00
dadus33 f1590c5098 Added travis. 2016-10-19 18:19:50 +03:00
dadus33 30aeb8882b Updated README.MD 2016-10-19 18:14:27 +03:00
dadus33 8b2803d752 Merge pull request #1 from Shynixn/master
Changed custom config handling to bukkit.
2016-10-19 18:07:15 +03:00
Shynixn 6d2c5907c1 Changed custom config handling to bukkit. 2016-10-18 17:26:45 +02:00
dadus33 a5a81f2360 Fixed config bug. 2016-10-17 19:15:42 +03:00
LongLiveVladerius@gmail.com f14a1660b5 Added compatibility with 1.7.X. Fixed DeluxeChat's and possibly other plugins' bugs by changing listener priority to LOWEST. 2016-10-14 18:05:47 +03:00
dadus33 f07f3edc3b Added compatibility with 1.7.X. Fixed DeluxeChat's and possibly other plugins' bugs by changing listener priority to LOWEST. 2016-10-14 15:21:52 +03:00
dadus33 c18118f846 Fixed console message bug. Added log4j. 2016-10-12 18:41:32 +03:00
LongLiveVladerius@gmail.com f1e6291e76 Fixed Item not displaying to user who sent it (using commands). Added commands feature. 2016-10-10 22:55:38 +03:00
LongLiveVladerius@gmail.com 97d28fe0f0 Updated way of getting player from packet and fixed translations. 2016-10-09 19:41:50 +03:00
LongLiveVladerius@gmail.com 7093fa2761 Updated config version. 2016-10-09 19:40:03 +03:00
LongLiveVladerius@gmail.com ce68890877 Updated config version. 2016-10-09 00:01:19 +03:00
dadus33 3a71045feb Updated config version. 2016-10-08 22:53:37 +03:00
LongLiveVladerius@gmail.com 4db713d93b Merge remote-tracking branch 'origin/master' 2016-10-08 22:49:37 +03:00
dadus33 910179326a Fixed translations feature. Added Metrics. 2016-10-08 22:49:32 +03:00
LongLiveVladerius@gmail.com 856c6decb2 Merge remote-tracking branch 'origin/master' 2016-10-08 22:45:13 +03:00
dadus33 d4c8b36ac6 Fixed translations feature. Added Metrics. 2016-10-08 22:45:08 +03:00
dadus33 0318246403 Fixed translations feature. Added Metrics. 2016-10-08 22:43:30 +03:00
LongLiveVladerius@gmail.com b38e62b138 Merge remote-tracking branch 'origin/master' 2016-10-08 20:16:06 +03:00
dadus33 bd62322adf Fixed bugged display of items (seemed to be random) 2016-10-08 20:15:45 +03:00
LongLiveVladerius@gmail.com 803b49c2ac Fixed bugged display of items (seemed to be random) 2016-10-08 20:11:19 +03:00
LongLiveVladerius@gmail.com 68c749c9d2 Fixed item display-name not showing in chat. 2016-10-07 17:01:36 +03:00
LongLiveVladerius@gmail.com 27def17f8a Attempt to fix messages sending different for each player. 2016-10-06 07:48:16 +03:00
dadus33 2b27cbbf64 Fixed parser not searching deep enough 2016-10-05 14:27:53 +03:00
dadus33 39a5fdb611 Added cooldown settings to config 2016-10-04 21:27:58 +03:00
LongLiveVladerius@gmail.com 7e961dc8ee Removed .idea 2016-10-04 21:09:17 +03:00
dadus33 ccbe90f7ee Create .gitignore 2016-10-04 20:54:52 +03:00
dadus33 ce6da93c57 Initial commit. 2016-10-04 18:49:59 +03:00
dadus33 2e8379dec9 Initial commit 2016-09-30 18:45:28 +03:00
8 changed files with 40 additions and 118 deletions

No files matched your search

-1
View File
@@ -1,5 +1,4 @@
.idea/
src/test/
target/
*.iml
dependency-reduced-pom.xml
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>me.dadus33</groupId>
<artifactId>ChatItem</artifactId>
<version>1.2.5</version>
<version>1.2.2</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -26,7 +26,7 @@ import java.util.logging.Level;
public class ChatItem extends JavaPlugin {
public final static int CFG_VER = 6;
public final static int CFG_VER = 4;
private static ChatItem instance;
private ChatEventListener chatEventListener;
private Log4jFilter filter;
@@ -5,7 +5,9 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
/**
* Created by Vlad on 30.09.2016.
*/
public class CIReload implements CommandExecutor {
@Override
@@ -1,9 +1,7 @@
package me.dadus33.chatitem.listeners;
import me.dadus33.chatitem.utils.Storage;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -14,35 +12,15 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class ChatEventListener implements Listener {
private Storage c;
private final static char SEPARATOR = ((char)0x0007);
public ChatEventListener(Storage storage) {
c = storage;
}
private int countOccurrences(String findStr, String str){
int lastIndex = 0;
int count = 0;
while(lastIndex != -1){
lastIndex = str.indexOf(findStr,lastIndex);
if(lastIndex != -1){
count ++;
lastIndex += findStr.length();
}
}
return count;
}
@SuppressWarnings("deprecation")
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onChat(AsyncPlayerChatEvent e) {
if(e.getMessage().indexOf(SEPARATOR)!=-1){ //If the BELL character is found, we have to remove it
String msg = e.getMessage().replace(Character.toString(SEPARATOR), "");
e.setMessage(msg);
}
boolean found = false;
for (String rep : c.PLACEHOLDERS)
@@ -71,58 +49,32 @@ public class ChatEventListener implements Listener {
s = s.replace(placeholder, c.PLACEHOLDERS.get(0));
}
int occurrences = countOccurrences(c.PLACEHOLDERS.get(0), s);
if(occurrences>c.LIMIT){
if(occurrences>c.MAX_OCCURRENCES){
e.setCancelled(true);
if(c.LIMIT_MESSAGE.isEmpty()){
return;
}
e.getPlayer().sendMessage(c.LIMIT_MESSAGE);
return;
}
}
String oldmsg = e.getMessage();
StringBuilder sb = new StringBuilder(oldmsg);
sb.append(SEPARATOR).append(e.getPlayer().getName());
e.setMessage(sb.toString());
Bukkit.getConsoleSender().sendMessage(String.format(e.getFormat(), e.getPlayer().getDisplayName(), oldmsg));
e.setMessage(e.getMessage().concat(e.getPlayer().getName()));
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.NORMAL)
public void onCommand(PlayerCommandPreprocessEvent e){
if(e.getMessage().indexOf(SEPARATOR)!=-1){ //If the BELL character is found, we have to remove it
String msg = e.getMessage().replace(Character.toString(SEPARATOR), "");
e.setMessage(msg);
}
Command cmd = Bukkit.getPluginCommand(e.getMessage().split(" ")[0].substring(1));
if(cmd==null){ //not a plugin command
return;
}
if(!c.ALLOWED_COMMANDS.contains(cmd)){
return;
}
boolean found = false;
for (String rep : c.PLACEHOLDERS) {
for (String rep : c.PLACEHOLDERS)
if (e.getMessage().contains(rep)) {
found = true;
break;
}
}
if (!found) {
return;
}
if (!e.getPlayer().hasPermission("chatitem.use")) {
e.setCancelled(true);
return;
}
if (e.getPlayer().getItemInHand().getType().equals(Material.AIR)) {
if (c.DENY_IF_NO_ITEM) {
e.setCancelled(true);
@@ -131,29 +83,38 @@ public class ChatEventListener implements Listener {
}
return;
}
String s = e.getMessage();
for(String placeholder : c.PLACEHOLDERS){
s = s.replace(placeholder, c.PLACEHOLDERS.get(0));
}
int occurrences = countOccurrences(c.PLACEHOLDERS.get(0), s);
if(occurrences>c.LIMIT){
if(occurrences>c.MAX_OCCURRENCES){
e.setCancelled(true);
if(c.LIMIT_MESSAGE.isEmpty()){
return;
}
e.getPlayer().sendMessage(c.LIMIT_MESSAGE);
return;
}
StringBuilder sb = new StringBuilder(e.getMessage());
sb.append(SEPARATOR).append(e.getPlayer().getName());
e.setMessage(sb.toString());
e.setMessage(e.getMessage().concat(e.getPlayer().getName()));
}
public void setStorage(Storage st) {
c = st;
}
private int countOccurrences(String findStr, String str){
int lastIndex = 0;
int count = 0;
while(lastIndex != -1){
lastIndex = str.indexOf(findStr,lastIndex);
if(lastIndex != -1){
count ++;
lastIndex += findStr.length();
}
}
return count;
}
}
@@ -61,7 +61,7 @@ public class ChatPacketListener extends PacketAdapter {
@SuppressWarnings("deprecation")
@Override
public void onPacketSending(PacketEvent e) {
if(ChatItem.post17) //actionbar messages are only available after 1.7
if(ChatItem.post17)
if (e.getPacket().getBytes().readSafely(0) == (byte) 2) {
return; //It means it's an actionbar message, and we ain't intercepting those
}
@@ -82,11 +82,6 @@ public class ChatPacketListener extends PacketAdapter {
if (!found) {
return; //then it's just a normal message without placeholders, so we leave it alone
}
if(json.lastIndexOf("\\u0007")==-1){ //if the message doesn't contain the BEL separator, then it's certainly NOT a message we want to parse
return;
}
//here we find the last player name in the string
int topIndex = -1;
String name = null;
for(Player p : Bukkit.getOnlinePlayers()){
@@ -103,18 +98,12 @@ public class ChatPacketListener extends PacketAdapter {
if(name==null){ //something went really bad, so we run away and hide
return;
}
//then we make sure the name is after the BEL separator.
if(json.lastIndexOf(name)!=json.lastIndexOf("\\u0007")+6){
return; //then it means somehow the message just contained a BEL character not inserted by our plugin
}
Player p = Bukkit.getPlayer(name);
StringBuilder buff = new StringBuilder(json);
buff.replace(topIndex-(name.length()+6), topIndex, ""); //we remove both the name and the separator from the json string
buff.replace(topIndex-name.length(), topIndex, "");
json = buff.toString();
//Item Styling
//STYLE BEGIN
ItemStack inHand = p.getItemInHand();
@@ -161,9 +150,10 @@ public class ChatPacketListener extends PacketAdapter {
}
}
}
//STYLE END
//STYLE END
String[] reps = new String[c.PLACEHOLDERS.size()];
c.PLACEHOLDERS.toArray(reps);
String message = null;
@@ -2,16 +2,12 @@ package me.dadus33.chatitem.utils;
import com.google.common.collect.ImmutableList;
import me.dadus33.chatitem.ChatItem;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
public class Storage {
@@ -24,11 +20,9 @@ public class Storage {
public final Boolean FORCE_ADD_AMOUNT;
public final Boolean DENY_IF_NO_ITEM;
public final String DENY_MESSAGE;
public final String LIMIT_MESSAGE;
public final String RELOAD_MESSAGE;
final Integer CONFIG_VERSION;
public final Integer LIMIT;
public final List<Command> ALLOWED_COMMANDS = new ArrayList<>();
public final Integer MAX_OCCURRENCES;
public Storage(FileConfiguration conf) {
Set<String> keys = conf.getConfigurationSection("Translations").getKeys(false);
@@ -43,7 +37,6 @@ public class Storage {
TRANSLATIONS.put(key, entry);
}
CONFIG_VERSION = conf.getInt("config-version");
LIMIT = conf.getInt("limit");
List<String> added = conf.getStringList("placeholders");
PLACEHOLDERS = ImmutableList.copyOf(added);
NAME_FORMAT = color(conf.getString("name-format"));
@@ -52,23 +45,8 @@ public class Storage {
FORCE_ADD_AMOUNT = conf.getBoolean("force-add-amount");
DENY_IF_NO_ITEM = conf.getBoolean("deny-if-no-item");
DENY_MESSAGE = color(conf.getString("deny-message"));
LIMIT_MESSAGE = color(conf.getString("limit-message"));
RELOAD_MESSAGE = color(conf.getString("reload-success"));
final List<String> cmds = conf.getStringList("commands");
Bukkit.getScheduler().runTaskLaterAsynchronously(ChatItem.getInstance(), new Runnable() {
@Override
public void run() {
for(String s : cmds){
Command c = Bukkit.getPluginCommand(s);
if(c!=null) {
ALLOWED_COMMANDS.add(Bukkit.getPluginCommand(s));
}
else
ChatItem.getInstance().getLogger().log(Level.WARNING, ChatColor.RED.toString().concat("Unknown command ")
.concat(s).concat(" found in config! Ignoring occurrence..."));
}
}
}, 100L);
MAX_OCCURRENCES = conf.getInt("max-occurrences");
}
+5 -13
View File
@@ -3,7 +3,7 @@
#https://www.spigotmc.org/resources/chatitem.19064/
#Version info, DON'T TOUCH
config-version: 6
config-version: 5
#The placeholders you want to use for the item. You can add as many as you want.
@@ -42,19 +42,11 @@ deny-message: "&c&lYou have no item in hand!"
# The message you will get after reloading the plugin using /cireload.
reload-success: "&b&lSuccessful reload!"
# Here you can choose which commands will the plugin attempt to parse. Console commands will all be ignored,
# however player commands will be taken into consideration. To add a command, simply add an element to the list
# bellow containing an alias (or name) for that command.
# Care should be taken with vanilla commands as those are not supported!
commands:
- "msg"
# The message a player will get when attempting to write more than 'max-occurrences' of placeholders in chat.
max-reached-message: "&c&lYou can only add 3 placeholders in chat!"
# Here you can set the limit on how many placeholders a user is allowed to use inside a message.
# Allowing too many placeholders can result in client crashes.
limit: 5
# The message a player will get when attempting to send a message with more placeholders then the allowed limit.
limit-message: "&c&lYou can only add 5 item placeholders per message!"
# The maximum number of occurences of the item placeholder in chat.
max-occurrences: 3