Skip to content

Commit

Permalink
2.1.2 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed Apr 29, 2020
1 parent b797749 commit cf27621
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 71 deletions.
37 changes: 24 additions & 13 deletions src/com/loohp/interactivechat/Commands.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.loohp.interactivechat;
package com.loohp.interactivechat;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -10,7 +10,6 @@
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.scheduler.BukkitRunnable;

import com.loohp.interactivechat.Updater.Updater;
import com.loohp.interactivechat.Utils.MaterialUtils;
Expand Down Expand Up @@ -48,16 +47,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (sender.hasPermission("interactivechat.update")) {
sender.sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat written by LOOHP!");
sender.sendMessage(ChatColor.GOLD + "[InteractiveChat] You are running InteractiveChat version: " + InteractiveChat.plugin.getDescription().getVersion());
new BukkitRunnable() {
public void run() {
String version = Updater.checkUpdate();
if (version.equals("latest")) {
sender.sendMessage(ChatColor.GREEN + "[InteractiveChat] You are running the latest version!");
} else {
Updater.sendUpdateMessage(version);
}
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
String version = Updater.checkUpdate();
if (version.equals("latest")) {
sender.sendMessage(ChatColor.GREEN + "[InteractiveChat] You are running the latest version!");
} else {
Updater.sendUpdateMessage(version);
}
}.runTaskAsynchronously(InteractiveChat.plugin);
});
} else {
sender.sendMessage(InteractiveChat.NoPermission);
}
Expand Down Expand Up @@ -107,16 +104,30 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
return tab;
}

if (args.length <= 1) {
switch (args.length) {
case 0:
if (sender.hasPermission("interactivechat.reload")) {
tab.add("reload");
}
if (sender.hasPermission("interactivechat.update")) {
tab.add("update");
}
return tab;
case 1:
if (sender.hasPermission("interactivechat.reload")) {
if ("reload".startsWith(args[0].toLowerCase())) {
tab.add("reload");
}
}
if (sender.hasPermission("interactivechat.update")) {
if ("update".startsWith(args[0].toLowerCase())) {
tab.add("update");
}
}
return tab;
default:
return tab;
}
return tab;
}

}
24 changes: 22 additions & 2 deletions src/com/loohp/interactivechat/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public static void reloadConfig() {
loadConfig();
}

public static void loadConfig() {
public static void loadConfig() {
InteractiveChat.aliasesMapping.clear();

InteractiveChat.FilterUselessColorCodes = getConfig().getBoolean("Settings.FilterUselessColorCodes");

InteractiveChat.AllowMention = getConfig().getBoolean("Chat.AllowMention");
Expand All @@ -46,6 +48,19 @@ public static void loadConfig() {
InteractiveChat.invPlaceholder = ChatColor.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Inventory.Keyword"));
InteractiveChat.enderPlaceholder = ChatColor.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.EnderChest.Keyword"));

for (String alias : getConfig().getStringList("ItemDisplay.Item.Aliases")) {
alias = ChatColor.translateAlternateColorCodes('&', alias);
InteractiveChat.aliasesMapping.put(alias, InteractiveChat.itemPlaceholder);
}
for (String alias : getConfig().getStringList("ItemDisplay.Inventory.Aliases")) {
alias = ChatColor.translateAlternateColorCodes('&', alias);
InteractiveChat.aliasesMapping.put(alias, InteractiveChat.invPlaceholder);
}
for (String alias : getConfig().getStringList("ItemDisplay.EnderChest.Aliases")) {
alias = ChatColor.translateAlternateColorCodes('&', alias);
InteractiveChat.aliasesMapping.put(alias, InteractiveChat.enderPlaceholder);
}

InteractiveChat.itemReplaceText = ChatColor.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Item.Text"));
InteractiveChat.invReplaceText = ChatColor.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Inventory.Text"));
InteractiveChat.enderReplaceText = ChatColor.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.EnderChest.Text"));
Expand Down Expand Up @@ -86,7 +101,12 @@ public static void loadConfig() {
InteractiveChat.placeholderList.add(InteractiveChat.enderPlaceholder);
}
for (int customNo = 1; getConfig().contains("CustomPlaceholders." + String.valueOf(customNo)) == true; customNo = customNo + 1) {
InteractiveChat.placeholderList.add(getConfig().getString("CustomPlaceholders." + String.valueOf(customNo) + ".Text"));
String placeholder = getConfig().getString("CustomPlaceholders." + String.valueOf(customNo) + ".Text");
InteractiveChat.placeholderList.add(placeholder);
for (String alias : getConfig().getStringList("CustomPlaceholders." + String.valueOf(customNo) + ".Aliases")) {
alias = ChatColor.translateAlternateColorCodes('&', alias);
InteractiveChat.aliasesMapping.put(alias, placeholder);
}
}

InteractiveChat.commandList = getConfig().getStringList("Settings.CommandsToParse");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import net.ess3.api.events.NickChangeEvent;

public class EssentialsHook implements Listener {
public class EssentialsNicknames implements Listener {

private static Essentials essen;
private static String prefix;
Expand Down
46 changes: 21 additions & 25 deletions src/com/loohp/interactivechat/InteractiveChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -18,11 +17,12 @@
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.loohp.interactivechat.Debug.Debug;
import com.loohp.interactivechat.Hooks.EssentialsHook;
import com.loohp.interactivechat.Hooks.EssentialsNicknames;
import com.loohp.interactivechat.Listeners.ChatPackets;
import com.loohp.interactivechat.Listeners.Events;
import com.loohp.interactivechat.Metrics.Charts;
import com.loohp.interactivechat.Metrics.Metrics;
import com.loohp.interactivechat.ObjectHolders.CommandPlaceholderGroup;
import com.loohp.interactivechat.ObjectHolders.CommandPlaceholderInfo;
import com.loohp.interactivechat.Utils.MaterialUtils;
import com.loohp.interactivechat.Utils.RarityUtils;

Expand All @@ -37,8 +37,8 @@ public class InteractiveChat extends JavaPlugin {
public static String space0 = "\u200B";
public static String space1 = "\u200A";

public static boolean ess3 = false;
public static boolean cm = false;
public static boolean EssentialsHook = false;
public static boolean ChatManagerHook = false;

public static boolean useItem = true;
public static boolean useInventory = true;
Expand Down Expand Up @@ -109,14 +109,16 @@ public class InteractiveChat extends JavaPlugin {
public static long mentionDuration = 2;

public static List<String> commandList = new ArrayList<String>();
public static HashMap<String, CommandPlaceholderGroup> commandPlaceholderMatch = new HashMap<String, CommandPlaceholderGroup>();

public static boolean UpdaterEnabled = true;
public static int UpdaterTaskID = -1;
public static HashMap<String, CommandPlaceholderInfo> commandPlaceholderMatch = new HashMap<String, CommandPlaceholderInfo>();

public static HashMap<Player, String> essenNick = new HashMap<Player, String>();

public static boolean FilterUselessColorCodes = true;

public static HashMap<String, String> aliasesMapping = new HashMap<String, String>();

public static boolean UpdaterEnabled = true;
public static int UpdaterTaskID = -1;

@Override
public void onEnable() {
Expand Down Expand Up @@ -160,8 +162,7 @@ public void onEnable() {
} else if (packageName.contains("1_8_R1")) {
version = "OLDlegacy1.8";
} else {
getServer().getConsoleSender().sendMessage(ChatColor.RED + "This version of minecraft is unsupported!");
plugin.getPluginLoader().disablePlugin(this);
getServer().getConsoleSender().sendMessage(ChatColor.RED + "[InteractiveChat] This version of minecraft is unsupported!");
}

getCommand("interactivechat").setExecutor(new Commands());
Expand All @@ -172,28 +173,23 @@ public void onEnable() {
ChatPackets.chatMessageListener();

if (Bukkit.getServer().getPluginManager().getPlugin("Essentials") != null) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "Interactive Chat has hooked into Essentials!");
ess3 = true;
getServer().getPluginManager().registerEvents(new EssentialsHook(), this);
EssentialsHook.setup();
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into Essentials!");
EssentialsHook = true;
getServer().getPluginManager().registerEvents(new EssentialsNicknames(), this);
EssentialsNicknames.setup();
}

if (Bukkit.getServer().getPluginManager().getPlugin("ChatManager") != null) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "Interactive Chat has hooked into ChatManager!");
cm = true;
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into ChatManager!");
ChatManagerHook = true;
}

MaterialUtils.setupLang();
RarityUtils.setupRarity();

metrics.addCustomChart(new Metrics.SingleLineChart("total_placeholders", new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return InteractiveChat.placeholderList.size();
}
}));
Charts.setup(metrics);

getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "InteractiveChat has been Enabled!");
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[InteractiveChat] InteractiveChat has been Enabled!");

for (Player player : Bukkit.getOnlinePlayers()) {
InteractiveChat.mentionCooldown.put(player, (System.currentTimeMillis() - 3000));
Expand All @@ -202,6 +198,6 @@ public Integer call() throws Exception {

@Override
public void onDisable() {
getServer().getConsoleSender().sendMessage(ChatColor.RED + "InteractiveChat has been Disabled!");
getServer().getConsoleSender().sendMessage(ChatColor.RED + "[InteractiveChat] InteractiveChat has been Disabled!");
}
}
12 changes: 6 additions & 6 deletions src/com/loohp/interactivechat/Listeners/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.bukkit.event.player.PlayerQuitEvent;

import com.loohp.interactivechat.InteractiveChat;
import com.loohp.interactivechat.ObjectHolders.CommandPlaceholderGroup;
import com.loohp.interactivechat.ObjectHolders.CommandPlaceholderInfo;
import com.loohp.interactivechat.Utils.CustomStringUtils;
import com.loohp.interactivechat.Utils.MessageUtils;

Expand All @@ -32,7 +32,7 @@ public void onJoin(PlayerJoinEvent event) {
}

@EventHandler
public void onJoin(PlayerQuitEvent event) {
public void onLeave(PlayerQuitEvent event) {
InteractiveChat.mentionCooldown.remove(event.getPlayer());
}

Expand All @@ -47,7 +47,7 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
String regexPlaceholder = CustomStringUtils.escapeMetaCharacters(placeholder);
String uuidmatch = "<" + UUID.randomUUID().toString() + ">";
command = command.replaceFirst(regexPlaceholder, uuidmatch);
InteractiveChat.commandPlaceholderMatch.put(uuidmatch, new CommandPlaceholderGroup(event.getPlayer(), placeholder, uuidmatch, InteractiveChat.commandPlaceholderMatch));
InteractiveChat.commandPlaceholderMatch.put(uuidmatch, new CommandPlaceholderInfo(event.getPlayer(), placeholder, uuidmatch, InteractiveChat.commandPlaceholderMatch));
event.setMessage(command);
break;
}
Expand All @@ -62,7 +62,7 @@ public void checkChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) {
return;
}
if (InteractiveChat.cm) {
if (InteractiveChat.ChatManagerHook) {
return;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public void checkChatforChatManager(AsyncPlayerChatEvent event) {
if (event.isCancelled()) {
return;
}
if (!InteractiveChat.cm) {
if (!InteractiveChat.ChatManagerHook) {
return;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public void onMention(AsyncPlayerChatEvent event) {
if (!player.getName().equals(player.getDisplayName())) {
playernames.add(player.getDisplayName());
}
if (InteractiveChat.ess3 == true) {
if (InteractiveChat.EssentialsHook == true) {
if (InteractiveChat.essenNick.containsKey(player)) {
playernames.add(InteractiveChat.essenNick.get(player));
}
Expand Down
20 changes: 20 additions & 0 deletions src/com/loohp/interactivechat/Metrics/Charts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.loohp.interactivechat.Metrics;

import java.util.concurrent.Callable;

import com.loohp.interactivechat.InteractiveChat;

public class Charts {

public static void setup(Metrics metrics) {

metrics.addCustomChart(new Metrics.SingleLineChart("total_placeholders", new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return InteractiveChat.placeholderList.size();
}
}));

}

}
2 changes: 1 addition & 1 deletion src/com/loohp/interactivechat/Modules/MentionDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static BaseComponent process(BaseComponent basecomponent, Player beenping
if (!names.contains(reciever.getName())) {
names.add(reciever.getName());
}
if (InteractiveChat.ess3) {
if (InteractiveChat.EssentialsHook) {
if (InteractiveChat.essenNick.containsKey(reciever)) {
names.add(InteractiveChat.essenNick.get(reciever));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PlayernameDisplay {
public static BaseComponent process(BaseComponent basecomponent, String messageKey, long unix) {
HashMap<String, Player> names = new HashMap<String, Player>();
Bukkit.getOnlinePlayers().forEach((each) -> names.put(each.getName(), each));
if (InteractiveChat.ess3) {
if (InteractiveChat.EssentialsHook) {
InteractiveChat.essenNick.forEach((player, name) -> names.put(name, player));
}

Expand Down
4 changes: 2 additions & 2 deletions src/com/loohp/interactivechat/Modules/ProcessCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.bukkit.entity.Player;

import com.loohp.interactivechat.InteractiveChat;
import com.loohp.interactivechat.ObjectHolders.CommandPlaceholderGroup;
import com.loohp.interactivechat.ObjectHolders.CommandPlaceholderInfo;
import com.loohp.interactivechat.ObjectHolders.ProcessCommandsReturn;
import com.loohp.interactivechat.Utils.CustomStringUtils;

Expand All @@ -28,7 +28,7 @@ public static ProcessCommandsReturn process(BaseComponent basecomponent) {
TextComponent textcomponent = (TextComponent) base;
String text = textcomponent.getText();
boolean contains = false;
for (Entry<String, CommandPlaceholderGroup> entry : InteractiveChat.commandPlaceholderMatch.entrySet()) {
for (Entry<String, CommandPlaceholderInfo> entry : InteractiveChat.commandPlaceholderMatch.entrySet()) {
if (text.contains(entry.getKey())) {
String newText = text.replace(entry.getKey(), entry.getValue().getPlaceholder());
textcomponent.setText(newText);
Expand Down
2 changes: 1 addition & 1 deletion src/com/loohp/interactivechat/Modules/SenderFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static Optional<Player> getSender(BaseComponent basecomponent, String mes

HashMap<String, Player> names = new HashMap<String, Player>();
Bukkit.getOnlinePlayers().forEach((each) -> names.put(each.getName(), each));
if (InteractiveChat.ess3) {
if (InteractiveChat.EssentialsHook) {
InteractiveChat.essenNick.forEach((player, name) -> names.put(name, player));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import com.loohp.interactivechat.InteractiveChat;

public class CommandPlaceholderGroup {
public class CommandPlaceholderInfo {

String placeholder;
String uuidmatch;
UUID sender;
HashMap<String, CommandPlaceholderGroup> map;
HashMap<String, CommandPlaceholderInfo> map;

public CommandPlaceholderGroup(Player sender, String placeholder, String uuidmatch, HashMap<String, CommandPlaceholderGroup> mapToRemoveFrom) {
public CommandPlaceholderInfo(Player sender, String placeholder, String uuidmatch, HashMap<String, CommandPlaceholderInfo> mapToRemoveFrom) {
this.placeholder = placeholder;
this.uuidmatch = uuidmatch;
this.sender = sender.getUniqueId();
Expand Down
Loading

0 comments on commit cf27621

Please sign in to comment.