From d1d1f4c4b8d3d6614320baea18e0790827b53e3f Mon Sep 17 00:00:00 2001 From: Aust1n46 Date: Sat, 6 May 2017 04:44:25 -0400 Subject: [PATCH] Changed cooldown code to be unbreakable this time (Lets all hope) --- .../Aust1n46/chat/MineverseChat.java | 13 ++++--- .../Aust1n46/chat/command/mute/Mute.java | 16 ++++---- .../Aust1n46/chat/listeners/ChatListener.java | 38 ++++++++++++------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/MineverseChat/mineverse/Aust1n46/chat/MineverseChat.java b/MineverseChat/mineverse/Aust1n46/chat/MineverseChat.java index 3d47cac..b5f83c7 100644 --- a/MineverseChat/mineverse/Aust1n46/chat/MineverseChat.java +++ b/MineverseChat/mineverse/Aust1n46/chat/MineverseChat.java @@ -482,11 +482,14 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener { @Override public void run() { for(MineverseChatPlayer p : MineverseChat.players) { - Calendar currentDate = Calendar.getInstance(); - SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss"); - String date = formatter.format(currentDate.getTime()); - String[] datearray = date.split(":"); - int time = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); + //Calendar currentDate = Calendar.getInstance(); + //SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss"); + //String date = formatter.format(currentDate.getTime()); + //String[] datearray = date.split(":"); + //int time = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); + + int time = (int) (System.currentTimeMillis() / 60000); + for(String c : p.getMutes().keySet()) { ChatChannel channel = ccInfo.getChannelInfo(c); int timemark = p.getMutes().get(channel.getName()); diff --git a/MineverseChat/mineverse/Aust1n46/chat/command/mute/Mute.java b/MineverseChat/mineverse/Aust1n46/chat/command/mute/Mute.java index 481a751..bef7261 100644 --- a/MineverseChat/mineverse/Aust1n46/chat/command/mute/Mute.java +++ b/MineverseChat/mineverse/Aust1n46/chat/command/mute/Mute.java @@ -1,8 +1,5 @@ package mineverse.Aust1n46.chat.command.mute; -import java.text.SimpleDateFormat; -import java.util.Calendar; - import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -65,11 +62,14 @@ public class Mute extends MineverseCommand { } if(channel.isMutable()) { try { - Calendar currentDate = Calendar.getInstance(); - SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss"); - String date = formatter.format(currentDate.getTime()); - String[] datearray = date.split(":"); - int datetime = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); + //Calendar currentDate = Calendar.getInstance(); + //SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss"); + //String date = formatter.format(currentDate.getTime()); + //String[] datearray = date.split(":"); + //int datetime = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); + + int datetime = (int) (System.currentTimeMillis() / 60000); + int time = Integer.parseInt(args[2]); if(time > 0) { player.addMute(channel.getName(), datetime + time); diff --git a/MineverseChat/mineverse/Aust1n46/chat/listeners/ChatListener.java b/MineverseChat/mineverse/Aust1n46/chat/listeners/ChatListener.java index 007c45d..eabfed4 100644 --- a/MineverseChat/mineverse/Aust1n46/chat/listeners/ChatListener.java +++ b/MineverseChat/mineverse/Aust1n46/chat/listeners/ChatListener.java @@ -409,14 +409,17 @@ public class ChatListener implements Listener { if(mcp.isMuted(eventChannel.getName())) { String timedMute = ""; if(mcp.getMutes().get(eventChannel.getName()).intValue() > 0) { - Calendar currentDate = Calendar.getInstance(); - SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss"); - String date = formatter.format(currentDate.getTime()); - String[] datearray = date.split(":"); - int datetime = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); + //Calendar currentDate = Calendar.getInstance(); + //SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss"); + //String date = formatter.format(currentDate.getTime()); + //String[] datearray = date.split(":"); + //int datetime = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); + + int time = (int) (System.currentTimeMillis() / 60000); + String keyword = "minutes"; - int time = mcp.getMutes().get(eventChannel.getName()).intValue(); - int remaining = time - datetime; + int timemark = mcp.getMutes().get(eventChannel.getName()).intValue(); + int remaining = timemark - time; if(remaining <= 0) remaining = 1; if(remaining == 1) keyword = "minute"; timedMute = ChatColor.RED + " for " + remaining + " more " + keyword; @@ -445,17 +448,21 @@ public class ChatListener implements Listener { Calendar currentDate = Calendar.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss"); String date = formatter.format(currentDate.getTime()); - String[] datearray = date.split(":"); - int time = (Integer.parseInt(datearray[0]) * 86400) + (Integer.parseInt(datearray[1]) * 3600) + (Integer.parseInt(datearray[2]) * 60) + (Integer.parseInt(datearray[3])); - int datetime = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); + //String[] datearray = date.split(":"); + //int time = (Integer.parseInt(datearray[0]) * 86400) + (Integer.parseInt(datearray[1]) * 3600) + (Integer.parseInt(datearray[2]) * 60) + (Integer.parseInt(datearray[3])); + //int datetime = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); + + int time = (int) (System.currentTimeMillis() / 1000); + if(eventChannel.hasCooldown()) { chCooldown = eventChannel.getCooldown(); } try { if(mcp.hasCooldown(eventChannel)) { int timemark = mcp.getCooldowns().get(eventChannel).intValue(); - if(time < timemark + chCooldown) { - int remaining = timemark + chCooldown - time; + System.out.println("Checking cooldown for " + mcp.getName() + " as time " + timemark + " current time as " + time); + if(time < timemark) { + int remaining = timemark - time; String keyword = "seconds"; if(remaining == 1) keyword = "second"; mcp.getPlayer().sendMessage(ChatColor.RED + "" + remaining + " " + keyword + " of cooldown remaining."); @@ -467,7 +474,8 @@ public class ChatListener implements Listener { } if(eventChannel.hasCooldown() && !event.isCancelled()) { if(!mcp.getPlayer().hasPermission("venturechat.cooldown.bypass")) { - mcp.addCooldown(eventChannel, time); + mcp.addCooldown(eventChannel, time + chCooldown); + System.out.println("Added new cooldown for " + mcp.getName() + " as current time " + (time + chCooldown)); } } } @@ -480,7 +488,9 @@ public class ChatListener implements Listener { int spamtime = mcp.getSpam().get(eventChannel).get(1); int spamtimeconfig = plugin.getConfig().getConfigurationSection("antispam").getInt("spamnumber"); int mutedfor = plugin.getConfig().getConfigurationSection("antispam").getInt("mutetime", 0); - if(time < spamtime + plugin.getConfig().getConfigurationSection("antispam").getInt("spamtime")) { + + int datetime = time/60; + if(datetime < spamtime + plugin.getConfig().getConfigurationSection("antispam").getInt("spamtime")) { if(spamcount + 1 >= spamtimeconfig) { mcp.addMute(eventChannel.getName(), datetime + mutedfor); String timedmute = "";