Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
769dfc3f8e | ||
|
|
8c061a057c | ||
|
|
e41a8e3db5 | ||
|
|
1fc0538ff4 | ||
|
|
fff868cf25 | ||
|
|
51b91b3c3d | ||
|
|
a20ed832f4 | ||
|
|
4ebbdc1c64 | ||
|
|
f0eb998f23 | ||
|
|
f1590c5098 | ||
|
|
30aeb8882b | ||
|
|
8b2803d752 | ||
|
|
6d2c5907c1 | ||
|
|
a5a81f2360 | ||
|
|
f14a1660b5 | ||
|
|
f07f3edc3b | ||
|
|
c18118f846 | ||
|
|
f1e6291e76 | ||
|
|
97d28fe0f0 | ||
|
|
7093fa2761 | ||
|
|
ce68890877 | ||
|
|
3a71045feb | ||
|
|
4db713d93b | ||
|
|
910179326a | ||
|
|
856c6decb2 | ||
|
|
d4c8b36ac6 | ||
|
|
0318246403 | ||
|
|
b38e62b138 | ||
|
|
bd62322adf | ||
|
|
803b49c2ac | ||
|
|
68c749c9d2 | ||
|
|
27def17f8a | ||
|
|
2b27cbbf64 | ||
|
|
39a5fdb611 | ||
|
|
7e961dc8ee | ||
|
|
ccbe90f7ee | ||
|
|
ce6da93c57 | ||
|
|
2e8379dec9 |
No files matched your search
@@ -1,5 +1,4 @@
|
||||
.idea/
|
||||
src/test/
|
||||
target/
|
||||
*.iml
|
||||
dependency-reduced-pom.xml
|
||||
@@ -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");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user