版本更新至:3.76
调整:开发框架改为 Gradle 新增:Language2 工具新增 [book] 类型
This commit is contained in:
62
src/main/java/me/skymc/taboolib/cooldown/CooldownPack.java
Normal file
62
src/main/java/me/skymc/taboolib/cooldown/CooldownPack.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package me.skymc.taboolib.cooldown;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@Deprecated
|
||||
public class CooldownPack {
|
||||
|
||||
private String plugin;
|
||||
private String name;
|
||||
private int seconds;
|
||||
|
||||
private HashMap<String, Long> data = new HashMap<>();
|
||||
|
||||
public CooldownPack(String n, int s) {
|
||||
this.name = n;
|
||||
this.seconds = s;
|
||||
this.plugin = "null";
|
||||
}
|
||||
|
||||
public String getPackName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getPackSeconds() {
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public String getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public void setPlugin(String p) {
|
||||
this.plugin = p;
|
||||
}
|
||||
|
||||
public void unRegister(String player) {
|
||||
data.remove(player);
|
||||
}
|
||||
|
||||
public int getCooldown(String player) {
|
||||
if (!data.containsKey(player)) {
|
||||
return 0;
|
||||
}
|
||||
int difference = (int) ((System.currentTimeMillis() - data.get(player)) / 1000);
|
||||
|
||||
return difference >= seconds ? 0 : seconds - difference;
|
||||
}
|
||||
|
||||
public boolean isCooldown(String player, int cutseconds) {
|
||||
if (!data.containsKey(player)) {
|
||||
data.put(player, System.currentTimeMillis());
|
||||
return false;
|
||||
}
|
||||
if ((getCooldown(player) - (cutseconds*1000)) <= 0) {
|
||||
data.put(player, System.currentTimeMillis());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
60
src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java
Normal file
60
src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package me.skymc.taboolib.cooldown;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
|
||||
@Deprecated
|
||||
public class CooldownUtils implements Listener {
|
||||
|
||||
private static ConcurrentHashMap<String, CooldownPack> packlist = new ConcurrentHashMap<>();
|
||||
|
||||
public static void register(CooldownPack pack) {
|
||||
packlist.put(pack.getPackName(), pack);
|
||||
MsgUtils.send("注册冷却包: " + pack.getPackName() + ", 时间: " + pack.getPackSeconds() + " 秒 (匿名注册)");
|
||||
}
|
||||
|
||||
public static void register(CooldownPack pack, Plugin plugin) {
|
||||
pack.setPlugin(plugin.getName());
|
||||
|
||||
packlist.put(pack.getPackName(), pack);
|
||||
MsgUtils.send("注册冷却包: " + pack.getPackName() + ", 时间: " + pack.getPackSeconds() + " 秒 (" + plugin.getName() + ")");
|
||||
}
|
||||
|
||||
public static void unregister(String name) {
|
||||
packlist.remove(name);
|
||||
|
||||
MsgUtils.send("注销冷却包: " + name + " (主动注销)");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void quit(PlayerQuitEvent e) {
|
||||
for (CooldownPack pack : packlist.values()) {
|
||||
if (!pack.isCooldown(e.getPlayer().getName(), 0)) {
|
||||
pack.unRegister(e.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disable(PluginDisableEvent e) {
|
||||
for (CooldownPack pack : packlist.values()) {
|
||||
if (pack.getPlugin().equals(e.getPlugin().getName())) {
|
||||
packlist.remove(pack.getPackName());
|
||||
|
||||
MsgUtils.send("注销冷却包: " + pack.getPackName() + " (自动注销)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.skymc.taboolib.cooldown.seconds;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class CooldownPack2 {
|
||||
|
||||
private String plugin;
|
||||
private String name;
|
||||
private int seconds;
|
||||
|
||||
private HashMap<String, Long> data = new HashMap<>();
|
||||
|
||||
public CooldownPack2(String n, int s) {
|
||||
this.name = n;
|
||||
this.seconds = s;
|
||||
this.plugin = "null";
|
||||
}
|
||||
|
||||
public String getPackName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getPackSeconds() {
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public String getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public void setPlugin(String p) {
|
||||
this.plugin = p;
|
||||
}
|
||||
|
||||
public void unRegister(String player) {
|
||||
data.remove(player);
|
||||
}
|
||||
|
||||
public int getCooldown(String player, int cutseconds) {
|
||||
if (!data.containsKey(player)) {
|
||||
return 0;
|
||||
}
|
||||
int difference = (int) ((System.currentTimeMillis() + cutseconds) - data.get(player));
|
||||
return difference >= seconds ? 0 : seconds - difference;
|
||||
}
|
||||
|
||||
public boolean isCooldown(String player, int cutseconds) {
|
||||
if (!data.containsKey(player)) {
|
||||
data.put(player, System.currentTimeMillis());
|
||||
return false;
|
||||
}
|
||||
if (getCooldown(player, cutseconds) <= 0) {
|
||||
data.put(player, System.currentTimeMillis());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package me.skymc.taboolib.cooldown.seconds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
|
||||
public class CooldownUtils2 implements Listener {
|
||||
|
||||
private static ConcurrentHashMap<String, CooldownPack2> packlist = new ConcurrentHashMap<>();
|
||||
|
||||
public static ConcurrentHashMap<String, CooldownPack2> getCooldownPacks() {
|
||||
return packlist;
|
||||
}
|
||||
|
||||
public static void register(CooldownPack2 pack) {
|
||||
packlist.put(pack.getPackName(), pack);
|
||||
// MsgUtils.send("注册冷却包: " + pack.getPackName() + ", 时间: " + pack.getPackSeconds() + " 秒 (匿名注册)");
|
||||
}
|
||||
|
||||
public static void register(CooldownPack2 pack, Plugin plugin) {
|
||||
pack.setPlugin(plugin.getName());
|
||||
|
||||
packlist.put(pack.getPackName(), pack);
|
||||
// MsgUtils.send("注册冷却包: " + pack.getPackName() + ", 时间: " + pack.getPackSeconds() + " 秒 (" + plugin.getName() + ")");
|
||||
}
|
||||
|
||||
public static void unregister(String name) {
|
||||
packlist.remove(name);
|
||||
|
||||
// MsgUtils.send("注销冷却包: " + name + " (主动注销)");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void quit(PlayerQuitEvent e) {
|
||||
for (CooldownPack2 pack : packlist.values()) {
|
||||
if (!pack.isCooldown(e.getPlayer().getName(), 0)) {
|
||||
pack.unRegister(e.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void disable(PluginDisableEvent e) {
|
||||
for (CooldownPack2 pack : packlist.values()) {
|
||||
if (pack.getPlugin().equals(e.getPlugin().getName())) {
|
||||
packlist.remove(pack.getPackName());
|
||||
|
||||
// MsgUtils.send("注销冷却包: " + pack.getPackName() + " (自动注销)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user