mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 11:40:40 +00:00
Format all classes in main package com.projectkorra.ProjectKorra
This commit is contained in:
parent
b33ca4a5e5
commit
f7f9767d2f
16 changed files with 3691 additions and 3812 deletions
|
@ -18,48 +18,29 @@ import com.projectkorra.rpg.WorldEvents;
|
|||
public class BendingManager implements Runnable {
|
||||
|
||||
public ProjectKorra plugin;
|
||||
|
||||
long time;
|
||||
long interval;
|
||||
|
||||
private final HashMap<World, Boolean> times = new HashMap<World, Boolean>(); // true if day time
|
||||
|
||||
public static HashMap<World, String> events = new HashMap<World, String>(); // holds any current event.
|
||||
|
||||
static final String defaultsozinscometmessage = "Sozin's Comet is passing overhead! Firebending is now at its most powerful.";
|
||||
static final String defaultsolareclipsemessage = "A solar eclipse is out! Firebenders are temporarily powerless.";
|
||||
static final String defaultsunrisemessage = "You feel the strength of the rising sun empowering your firebending.";
|
||||
static final String defaultsunsetmessage = "You feel the empowering of your firebending subside as the sun sets.";
|
||||
static final String defaultmoonrisemessage = "You feel the strength of the rising moon empowering your waterbending.";
|
||||
static final String defaultfullmoonrisemessage = "A full moon is rising, empowering your waterbending like never before.";
|
||||
static final String defaultlunareclipsemessage = "A lunar eclipse is out! Waterbenders are temporarily powerless.";
|
||||
static final String defaultmoonsetmessage = "You feel the empowering of your waterbending subside as the moon sets.";
|
||||
static final String DEFAULT_SOZINS_COMET_MESSAGE = "Sozin's Comet is passing overhead! Firebending is now at its most powerful.";
|
||||
static final String DEFAULT_SOLAR_ECLIPSE_MESSAGE = "A solar eclipse is out! Firebenders are temporarily powerless.";
|
||||
|
||||
static final String DEFAULT_SUNRISE_MESSAGE = "You feel the strength of the rising sun empowering your firebending.";
|
||||
static final String DEFAULT_SUNSET_MESSAGE = "You feel the empowering of your firebending subside as the sun sets.";
|
||||
|
||||
static final String DEFAULT_MOONRISE_MESSAGE = "You feel the strength of the rising moon empowering your waterbending.";
|
||||
static final String DEFAULT_FULL_MOONRISE_MESSAGE = "A full moon is rising, empowering your waterbending like never before.";
|
||||
static final String DEFAULT_LUNAR_ECLIPSE_MESSAGE = "A lunar eclipse is out! Waterbenders are temporarily powerless.";
|
||||
static final String DEFAULT_MOONSET_MESSAGE = "You feel the empowering of your waterbending subside as the moon sets.";
|
||||
|
||||
long time;
|
||||
long interval;
|
||||
private final HashMap<World, Boolean> times = new HashMap<World, Boolean>(); // true if day time
|
||||
|
||||
public BendingManager(ProjectKorra plugin) {
|
||||
this.plugin = plugin;
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
interval = System.currentTimeMillis() - time;
|
||||
time = System.currentTimeMillis();
|
||||
ProjectKorra.time_step = interval;
|
||||
|
||||
AvatarState.manageAvatarStates();
|
||||
TempPotionEffect.progressAll();
|
||||
handleDayNight();
|
||||
Flight.handle();
|
||||
RapidPunch.startPunchAll();
|
||||
RevertChecker.revertAirBlocks();
|
||||
ChiComboManager.handleParalysis();
|
||||
HorizontalVelocityTracker.updateAll();
|
||||
handleCooldowns();
|
||||
} catch (Exception e) {
|
||||
GeneralMethods.stopBending();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void handleCooldowns() {
|
||||
for (String bP: BendingPlayer.players.keySet()) {
|
||||
BendingPlayer bPlayer = BendingPlayer.players.get(bP);
|
||||
|
@ -91,11 +72,9 @@ public class BendingManager implements Runnable {
|
|||
if (GeneralMethods.hasRPG()) {
|
||||
if (RPGMethods.isLunarEclipse(world)) {
|
||||
events.put(world, WorldEvents.LunarEclipse.toString());
|
||||
}
|
||||
else if (WaterMethods.isFullMoon(world)) {
|
||||
} else if (WaterMethods.isFullMoon(world)) {
|
||||
events.put(world, "FullMoon");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
events.put(world, "");
|
||||
}
|
||||
} else {
|
||||
|
@ -112,23 +91,23 @@ public class BendingManager implements Runnable {
|
|||
if (GeneralMethods.isBender(player.getName(), Element.Water)) {
|
||||
if (GeneralMethods.hasRPG()) {
|
||||
if (RPGMethods.isLunarEclipse(world)) {
|
||||
player.sendMessage(WaterMethods.getWaterColor() + defaultlunareclipsemessage);
|
||||
player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_LUNAR_ECLIPSE_MESSAGE);
|
||||
} else if (WaterMethods.isFullMoon(world)) {
|
||||
player.sendMessage(WaterMethods.getWaterColor() + defaultfullmoonrisemessage);
|
||||
player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_FULL_MOONRISE_MESSAGE);
|
||||
} else {
|
||||
player.sendMessage(WaterMethods.getWaterColor() + defaultmoonrisemessage);
|
||||
player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_MOONRISE_MESSAGE);
|
||||
}
|
||||
} else {
|
||||
if (WaterMethods.isFullMoon(world)) {
|
||||
player.sendMessage(WaterMethods.getWaterColor() + defaultfullmoonrisemessage);
|
||||
player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_FULL_MOONRISE_MESSAGE);
|
||||
} else {
|
||||
player.sendMessage(WaterMethods.getWaterColor() + defaultmoonrisemessage);
|
||||
player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_MOONRISE_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GeneralMethods.isBender(player.getName(), Element.Fire)) {
|
||||
if(player.hasPermission("bending.message.daymessage")) return;
|
||||
player.sendMessage(FireMethods.getFireColor() + defaultsunsetmessage);
|
||||
player.sendMessage(FireMethods.getFireColor() + DEFAULT_SUNSET_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,11 +118,9 @@ public class BendingManager implements Runnable {
|
|||
if (GeneralMethods.hasRPG()) {
|
||||
if (RPGMethods.isSozinsComet(world)) {
|
||||
events.put(world, WorldEvents.SozinsComet.toString());
|
||||
}
|
||||
else if (RPGMethods.isSolarEclipse(world) && !RPGMethods.isLunarEclipse(world)) {
|
||||
} else if (RPGMethods.isSolarEclipse(world) && !RPGMethods.isLunarEclipse(world)) {
|
||||
events.put(world, WorldEvents.SolarEclipse.toString());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
events.put(world, "");
|
||||
}
|
||||
} else {
|
||||
|
@ -151,25 +128,45 @@ public class BendingManager implements Runnable {
|
|||
}
|
||||
for (Player player: world.getPlayers()) {
|
||||
if (GeneralMethods.isBender(player.getName(), Element.Water) && player.hasPermission("bending.message.nightmessage")) {
|
||||
player.sendMessage(WaterMethods.getWaterColor() + defaultmoonsetmessage);
|
||||
player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_MOONSET_MESSAGE);
|
||||
}
|
||||
if (GeneralMethods.isBender(player.getName(), Element.Fire) && player.hasPermission("bending.message.daymessage")) {
|
||||
if (GeneralMethods.hasRPG()) {
|
||||
if (RPGMethods.isSozinsComet(world)) {
|
||||
player.sendMessage(FireMethods.getFireColor() + defaultsozinscometmessage);
|
||||
player.sendMessage(FireMethods.getFireColor() + DEFAULT_SOZINS_COMET_MESSAGE);
|
||||
} else if (RPGMethods.isSolarEclipse(world) && !RPGMethods.isLunarEclipse(world)) {
|
||||
player.sendMessage(FireMethods.getFireColor() + defaultsolareclipsemessage);
|
||||
player.sendMessage(FireMethods.getFireColor() + DEFAULT_SOLAR_ECLIPSE_MESSAGE);
|
||||
} else {
|
||||
player.sendMessage(FireMethods.getFireColor() + defaultsunrisemessage);
|
||||
player.sendMessage(FireMethods.getFireColor() + DEFAULT_SUNRISE_MESSAGE);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(FireMethods.getFireColor() + defaultsunrisemessage);
|
||||
player.sendMessage(FireMethods.getFireColor() + DEFAULT_SUNRISE_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
interval = System.currentTimeMillis() - time;
|
||||
time = System.currentTimeMillis();
|
||||
ProjectKorra.time_step = interval;
|
||||
|
||||
AvatarState.manageAvatarStates();
|
||||
TempPotionEffect.progressAll();
|
||||
handleDayNight();
|
||||
Flight.handle();
|
||||
RapidPunch.startPunchAll();
|
||||
RevertChecker.revertAirBlocks();
|
||||
ChiComboManager.handleParalysis();
|
||||
HorizontalVelocityTracker.updateAll();
|
||||
handleCooldowns();
|
||||
} catch (Exception e) {
|
||||
GeneralMethods.stopBending();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public class BendingPlayer {
|
|||
this.player = player;
|
||||
this.elements = elements;
|
||||
this.setAbilities(abilities);
|
||||
cooldowns = new ConcurrentHashMap<String, Long>();
|
||||
this.permaRemoved = permaRemoved;
|
||||
cooldowns = new ConcurrentHashMap<String, Long>();
|
||||
isToggled = true;
|
||||
blockedChi = false;
|
||||
|
||||
|
@ -41,87 +41,72 @@ public class BendingPlayer {
|
|||
PKListener.login(this);
|
||||
}
|
||||
|
||||
public boolean isOnCooldown(String ability) {
|
||||
return this.cooldowns.containsKey(ability);
|
||||
}
|
||||
|
||||
public void addCooldown(String ability, long cooldown) {
|
||||
PlayerCooldownChangeEvent event = new PlayerCooldownChangeEvent(Bukkit.getPlayer(uuid), ability, Result.ADDED);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled())
|
||||
if(!event.isCancelled()) {
|
||||
this.cooldowns.put(ability, cooldown + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void removeCooldown(String ability) {
|
||||
PlayerCooldownChangeEvent event = new PlayerCooldownChangeEvent(Bukkit.getPlayer(uuid), ability, Result.REMOVED);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled())
|
||||
this.cooldowns.remove(ability);
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public List<Element> getElements() {
|
||||
return this.elements;
|
||||
}
|
||||
|
||||
public HashMap<Integer, String> getAbilities() {
|
||||
return this.abilities;
|
||||
}
|
||||
|
||||
public boolean isPermaRemoved() {
|
||||
return this.permaRemoved;
|
||||
}
|
||||
}
|
||||
|
||||
public void addElement(Element e) {
|
||||
this.elements.add(e);
|
||||
}
|
||||
|
||||
public boolean hasElement(Element e) {
|
||||
return this.elements.contains(e);
|
||||
public void blockChi() {
|
||||
blockedChi = true;
|
||||
}
|
||||
|
||||
public void setElement(Element e) {
|
||||
this.elements.clear();
|
||||
this.elements.add(e);
|
||||
}
|
||||
|
||||
public boolean canBeSlowed() {
|
||||
return (System.currentTimeMillis() > slowTime);
|
||||
}
|
||||
|
||||
public void slow(long cooldown) {
|
||||
slowTime = System.currentTimeMillis() + cooldown;
|
||||
public HashMap<Integer, String> getAbilities() {
|
||||
return this.abilities;
|
||||
}
|
||||
|
||||
public void toggleTremorsense() {
|
||||
tremorsense = !tremorsense;
|
||||
public List<Element> getElements() {
|
||||
return this.elements;
|
||||
}
|
||||
|
||||
public boolean isTremorsensing() {
|
||||
return tremorsense;
|
||||
public String getPlayerName() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public void blockChi() {
|
||||
blockedChi = true;
|
||||
public UUID getUUID() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void unblockChi() {
|
||||
blockedChi = false;
|
||||
public boolean hasElement(Element e) {
|
||||
return this.elements.contains(e);
|
||||
}
|
||||
|
||||
public boolean isChiBlocked() {
|
||||
return blockedChi;
|
||||
return this.blockedChi;
|
||||
}
|
||||
|
||||
|
||||
public boolean isOnCooldown(String ability) {
|
||||
return this.cooldowns.containsKey(ability);
|
||||
}
|
||||
|
||||
public boolean isPermaRemoved() {
|
||||
return this.permaRemoved;
|
||||
}
|
||||
|
||||
public boolean isToggled() {
|
||||
return isToggled;
|
||||
return this.isToggled;
|
||||
}
|
||||
|
||||
public boolean isTremorsensing() {
|
||||
return this.tremorsense;
|
||||
}
|
||||
|
||||
public void removeCooldown(String ability) {
|
||||
PlayerCooldownChangeEvent event = new PlayerCooldownChangeEvent(Bukkit.getPlayer(uuid), ability, Result.REMOVED);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()) {
|
||||
this.cooldowns.remove(ability);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAbilities(HashMap<Integer, String> abilities) {
|
||||
|
@ -130,4 +115,21 @@ public class BendingPlayer {
|
|||
DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + i + " = '" + (abilities.get(i) == null ? null: abilities.get(i)) + "' WHERE uuid = '" + uuid + "'");
|
||||
}
|
||||
}
|
||||
|
||||
public void setElement(Element e) {
|
||||
this.elements.clear();
|
||||
this.elements.add(e);
|
||||
}
|
||||
|
||||
public void slow(long cooldown) {
|
||||
slowTime = System.currentTimeMillis() + cooldown;
|
||||
}
|
||||
|
||||
public void toggleTremorsense() {
|
||||
tremorsense = !tremorsense;
|
||||
}
|
||||
|
||||
public void unblockChi() {
|
||||
blockedChi = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
package com.projectkorra.ProjectKorra;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.projectkorra.ProjectKorra.Ability.Combo.ComboAbilityModule;
|
||||
import com.projectkorra.ProjectKorra.Utilities.ClickType;
|
||||
import com.projectkorra.ProjectKorra.airbending.AirCombo;
|
||||
import com.projectkorra.ProjectKorra.firebending.FireCombo;
|
||||
import com.projectkorra.ProjectKorra.waterbending.WaterCombo;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ComboManager {
|
||||
private static final long CLEANUP_DELAY = 10000;
|
||||
public static ConcurrentHashMap<String, ArrayList<AbilityInformation>> recentlyUsedAbilities = new ConcurrentHashMap<String, ArrayList<AbilityInformation>>();
|
||||
public static ArrayList<ComboAbility> comboAbilityList = new ArrayList<ComboAbility>();
|
||||
public static HashMap<String, String> authors = new HashMap<String, String>();
|
||||
public static HashMap<String, String> descriptions = new HashMap<String, String>();
|
||||
public static HashMap<String, String> instructions = new HashMap<String, String>();
|
||||
public static HashMap<String, String> authors = new HashMap<String, String>();
|
||||
|
||||
|
||||
public ComboManager() {
|
||||
ArrayList<AbilityInformation> fireKick = new ArrayList<AbilityInformation>();
|
||||
fireKick.add(new AbilityInformation("FireBlast", ClickType.LEFT_CLICK));
|
||||
|
@ -154,94 +154,6 @@ public class ComboManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static class AbilityInformation {
|
||||
private String abilityName;
|
||||
private ClickType clickType;
|
||||
private long time;
|
||||
|
||||
public AbilityInformation(String name, ClickType type, long time) {
|
||||
this.abilityName = name;
|
||||
this.clickType = type;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public AbilityInformation(String name, ClickType type) {
|
||||
this(name, type, 0);
|
||||
}
|
||||
|
||||
public String getAbilityName() {
|
||||
return abilityName;
|
||||
}
|
||||
|
||||
public void setAbilityName(String abilityName) {
|
||||
this.abilityName = abilityName;
|
||||
}
|
||||
|
||||
public ClickType getClickType() {
|
||||
return clickType;
|
||||
}
|
||||
|
||||
public void setClickType(ClickType clickType) {
|
||||
this.clickType = clickType;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return abilityName + " " + clickType + " " + time;
|
||||
}
|
||||
|
||||
public boolean equalsWithoutTime(AbilityInformation info) {
|
||||
return this.getAbilityName().equals(info.getAbilityName()) && this.getClickType().equals(info.getClickType());
|
||||
}
|
||||
}
|
||||
|
||||
public static class ComboAbility {
|
||||
private String name;
|
||||
private ArrayList<AbilityInformation> abilities;
|
||||
private Object comboType;
|
||||
|
||||
public ComboAbility(String name, ArrayList<AbilityInformation> abilities, Object comboType) {
|
||||
this.name = name;
|
||||
this.abilities = abilities;
|
||||
this.comboType = comboType;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ArrayList<AbilityInformation> getAbilities() {
|
||||
return abilities;
|
||||
}
|
||||
|
||||
public void setAbilities(ArrayList<AbilityInformation> abilities) {
|
||||
this.abilities = abilities;
|
||||
}
|
||||
|
||||
public Object getComboType() {
|
||||
return comboType;
|
||||
}
|
||||
|
||||
public void setComboType(Object comboType) {
|
||||
this.comboType = comboType;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static void addRecentAbility(Player player, AbilityInformation info) {
|
||||
ArrayList<AbilityInformation> list;
|
||||
String name = player.getName();
|
||||
|
@ -254,21 +166,6 @@ public class ComboManager {
|
|||
recentlyUsedAbilities.put(name, list);
|
||||
}
|
||||
|
||||
public static ArrayList<AbilityInformation> getRecentlyUsedAbilities(Player player, int amount) {
|
||||
String name = player.getName();
|
||||
if (!recentlyUsedAbilities.containsKey(name))
|
||||
return new ArrayList<AbilityInformation>();
|
||||
|
||||
ArrayList<AbilityInformation> list = recentlyUsedAbilities.get(name);
|
||||
if (list.size() < amount)
|
||||
return new ArrayList<AbilityInformation>(list);
|
||||
|
||||
ArrayList<AbilityInformation> tempList = new ArrayList<AbilityInformation>();
|
||||
for (int i = 0; i < amount; i++)
|
||||
tempList.add(0, list.get(list.size() - 1 - i));
|
||||
return tempList;
|
||||
}
|
||||
|
||||
public static ComboAbility checkForValidCombo(Player player) {
|
||||
ArrayList<AbilityInformation> playerCombo = getRecentlyUsedAbilities(player, 8);
|
||||
for (ComboAbility customAbility : comboAbilityList) {
|
||||
|
@ -291,14 +188,6 @@ public class ComboManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void startCleanupTask() {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
cleanupOldCombos();
|
||||
}
|
||||
}.runTaskTimer(ProjectKorra.plugin, 0, CLEANUP_DELAY);
|
||||
}
|
||||
|
||||
public static void cleanupOldCombos() {
|
||||
Enumeration<String> keys = recentlyUsedAbilities.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
|
@ -317,4 +206,115 @@ public class ComboManager {
|
|||
recentlyUsedAbilities.put(name, combos);
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<AbilityInformation> getRecentlyUsedAbilities(Player player, int amount) {
|
||||
String name = player.getName();
|
||||
if (!recentlyUsedAbilities.containsKey(name))
|
||||
return new ArrayList<AbilityInformation>();
|
||||
|
||||
ArrayList<AbilityInformation> list = recentlyUsedAbilities.get(name);
|
||||
if (list.size() < amount)
|
||||
return new ArrayList<AbilityInformation>(list);
|
||||
|
||||
ArrayList<AbilityInformation> tempList = new ArrayList<AbilityInformation>();
|
||||
for (int i = 0; i < amount; i++)
|
||||
tempList.add(0, list.get(list.size() - 1 - i));
|
||||
return tempList;
|
||||
}
|
||||
|
||||
public static void startCleanupTask() {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
cleanupOldCombos();
|
||||
}
|
||||
}.runTaskTimer(ProjectKorra.plugin, 0, CLEANUP_DELAY);
|
||||
}
|
||||
|
||||
public static class AbilityInformation {
|
||||
private String abilityName;
|
||||
private ClickType clickType;
|
||||
private long time;
|
||||
|
||||
public AbilityInformation(String name, ClickType type) {
|
||||
this(name, type, 0);
|
||||
}
|
||||
|
||||
public AbilityInformation(String name, ClickType type, long time) {
|
||||
this.abilityName = name;
|
||||
this.clickType = type;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public boolean equalsWithoutTime(AbilityInformation info) {
|
||||
return this.getAbilityName().equals(info.getAbilityName()) && this.getClickType().equals(info.getClickType());
|
||||
}
|
||||
|
||||
public String getAbilityName() {
|
||||
return abilityName;
|
||||
}
|
||||
|
||||
public ClickType getClickType() {
|
||||
return clickType;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setAbilityName(String abilityName) {
|
||||
this.abilityName = abilityName;
|
||||
}
|
||||
|
||||
public void setClickType(ClickType clickType) {
|
||||
this.clickType = clickType;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return abilityName + " " + clickType + " " + time;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ComboAbility {
|
||||
private String name;
|
||||
private ArrayList<AbilityInformation> abilities;
|
||||
private Object comboType;
|
||||
|
||||
public ComboAbility(String name, ArrayList<AbilityInformation> abilities, Object comboType) {
|
||||
this.name = name;
|
||||
this.abilities = abilities;
|
||||
this.comboType = comboType;
|
||||
}
|
||||
|
||||
public ArrayList<AbilityInformation> getAbilities() {
|
||||
return abilities;
|
||||
}
|
||||
|
||||
public Object getComboType() {
|
||||
return comboType;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setAbilities(ArrayList<AbilityInformation> abilities) {
|
||||
this.abilities = abilities;
|
||||
}
|
||||
|
||||
public void setComboType(Object comboType) {
|
||||
this.comboType = comboType;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -19,11 +19,12 @@ import com.projectkorra.ProjectKorra.waterbending.WaterSpout;
|
|||
public class Flight {
|
||||
|
||||
private static ConcurrentHashMap<Player, Flight> instances = new ConcurrentHashMap<Player, Flight>();
|
||||
|
||||
private static long duration = 5000;
|
||||
|
||||
|
||||
private Player player = null, source = null;
|
||||
|
||||
private boolean couldFly = false, wasFlying = false;
|
||||
|
||||
private long time;
|
||||
|
||||
public Flight(Player player) {
|
||||
|
@ -31,14 +32,12 @@ public class Flight {
|
|||
}
|
||||
|
||||
public Flight(Player player, Player source) {
|
||||
|
||||
if (instances.containsKey(player)) {
|
||||
Flight flight = instances.get(player);
|
||||
flight.refresh(source);
|
||||
instances.replace(player, flight);
|
||||
return;
|
||||
}
|
||||
|
||||
couldFly = player.getAllowFlight();
|
||||
wasFlying = player.isFlying();
|
||||
this.player = player;
|
||||
|
@ -46,7 +45,7 @@ public class Flight {
|
|||
time = System.currentTimeMillis();
|
||||
instances.put(player, this);
|
||||
}
|
||||
|
||||
|
||||
public static Player getLaunchedBy(Player player) {
|
||||
if (instances.containsKey(player)) {
|
||||
return instances.get(player).source;
|
||||
|
@ -54,28 +53,8 @@ public class Flight {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void revert() {
|
||||
if (player == null) {
|
||||
instances.remove(player);
|
||||
return;
|
||||
}
|
||||
player.setAllowFlight(couldFly);
|
||||
player.setFlying(wasFlying);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
instances.remove(player);
|
||||
}
|
||||
|
||||
private void refresh(Player source) {
|
||||
this.source = source;
|
||||
time = System.currentTimeMillis();
|
||||
instances.replace(player, this);
|
||||
}
|
||||
|
||||
|
||||
public static void handle() {
|
||||
|
||||
ArrayList<Player> players = new ArrayList<Player>();
|
||||
ArrayList<Player> newflyingplayers = new ArrayList<Player>();
|
||||
ArrayList<Player> avatarstateplayers = new ArrayList<Player>();
|
||||
|
@ -126,11 +105,8 @@ public class Flight {
|
|||
flight.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void removeAll() {
|
||||
for (Player player : instances.keySet()) {
|
||||
Flight flight = instances.get(player);
|
||||
|
@ -144,4 +120,23 @@ public class Flight {
|
|||
}
|
||||
}
|
||||
|
||||
private void refresh(Player source) {
|
||||
this.source = source;
|
||||
time = System.currentTimeMillis();
|
||||
instances.replace(player, this);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
instances.remove(player);
|
||||
}
|
||||
|
||||
public void revert() {
|
||||
if (player == null) {
|
||||
instances.remove(player);
|
||||
return;
|
||||
}
|
||||
player.setAllowFlight(couldFly);
|
||||
player.setFlying(wasFlying);
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -8,19 +8,19 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public class Information {
|
||||
|
||||
private Player player;
|
||||
private long time;
|
||||
private Block block;
|
||||
private Location location;
|
||||
private Material type;
|
||||
private static int ID = Integer.MIN_VALUE;
|
||||
private String string;
|
||||
private int id;
|
||||
private int integer;
|
||||
private long time;
|
||||
private double value;
|
||||
private byte data;
|
||||
private String string;
|
||||
|
||||
private Block block;
|
||||
private BlockState state;
|
||||
|
||||
private static int ID = Integer.MIN_VALUE;
|
||||
private int id;
|
||||
private Location location;
|
||||
private Material type;
|
||||
private Player player;
|
||||
|
||||
public Information() {
|
||||
id = ID++;
|
||||
|
@ -29,88 +29,88 @@ public class Information {
|
|||
}
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setState(BlockState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public BlockState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setString(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setBlock(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setType(Material type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Material getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setInteger(int integer) {
|
||||
this.integer = integer;
|
||||
}
|
||||
|
||||
public int getInteger() {
|
||||
return integer;
|
||||
}
|
||||
|
||||
public void setDouble(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public double getDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setData(byte data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public byte getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public double getDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getInteger() {
|
||||
return integer;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public BlockState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public Material getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setBlock(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public void setData(byte data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setDouble(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void setInteger(int integer) {
|
||||
this.integer = integer;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void setState(BlockState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void setString(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public void setType(Material type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
|
@ -135,57 +135,191 @@ public class MetricsLite {
|
|||
}
|
||||
|
||||
/**
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send
|
||||
* the initial data to the metrics backend, and then after that it will post in increments of
|
||||
* PING_INTERVAL * 1200 ticks.
|
||||
* Appends a json encoded key/value pair to the given string builder.
|
||||
*
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
* @param json
|
||||
* @param key
|
||||
* @param value
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
// Did we opt out?
|
||||
if (isOptOut()) {
|
||||
return false;
|
||||
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
||||
boolean isValueNumeric = false;
|
||||
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
}
|
||||
|
||||
// Is metrics already running?
|
||||
if (task != null) {
|
||||
return true;
|
||||
}
|
||||
if (json.charAt(json.length() - 1) != '{') {
|
||||
json.append(',');
|
||||
}
|
||||
|
||||
// Begin hitting the server with glorious data
|
||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
|
||||
private boolean firstPost = true;
|
||||
if (isValueNumeric) {
|
||||
json.append(value);
|
||||
} else {
|
||||
json.append(escapeJSON(value));
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Escape a string to create a valid JSON string
|
||||
*
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private static String escapeJSON(String text) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
||||
// it is not a interval ping, so it evaluates to FALSE
|
||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
||||
postPlugin(!firstPost);
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
char chr = text.charAt(index);
|
||||
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (IOException e) {
|
||||
if (debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
builder.append(chr);
|
||||
break;
|
||||
case '\b':
|
||||
builder.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
builder.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
builder.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u" + t.substring(t.length() - 4));
|
||||
} else {
|
||||
builder.append(chr);
|
||||
}
|
||||
}, 0, PING_INTERVAL * 1200);
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.append('"');
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* GZip compress a string of bytes
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static byte[] gzip(String input) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gzos != null) try {
|
||||
gzos.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void disable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut()) {
|
||||
configuration.set("opt-out", true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (task == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile() {
|
||||
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
|
||||
// is to abuse the plugin object we already have
|
||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||
// pluginsFolder => base/plugins/
|
||||
// The base is not necessarily relative to the startup directory.
|
||||
File pluginsFolder = plugin.getDataFolder().getParentFile();
|
||||
|
||||
// return => base/plugins/PluginMetrics/config.yml
|
||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,66 +348,6 @@ public class MetricsLite {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (task == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void disable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut()) {
|
||||
configuration.set("opt-out", true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile() {
|
||||
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
|
||||
// is to abuse the plugin object we already have
|
||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||
// pluginsFolder => base/plugins/
|
||||
// The base is not necessarily relative to the startup directory.
|
||||
File pluginsFolder = plugin.getDataFolder().getParentFile();
|
||||
|
||||
// return => base/plugins/PluginMetrics/config.yml
|
||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*/
|
||||
|
@ -382,132 +456,58 @@ public class MetricsLite {
|
|||
}
|
||||
|
||||
/**
|
||||
* GZip compress a string of bytes
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send
|
||||
* the initial data to the metrics backend, and then after that it will post in increments of
|
||||
* PING_INTERVAL * 1200 ticks.
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
*/
|
||||
public static byte[] gzip(String input) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gzos != null) try {
|
||||
gzos.close();
|
||||
} catch (IOException ignore) {
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
// Did we opt out?
|
||||
if (isOptOut()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a json encoded key/value pair to the given string builder.
|
||||
*
|
||||
* @param json
|
||||
* @param key
|
||||
* @param value
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
||||
boolean isValueNumeric = false;
|
||||
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
// Is metrics already running?
|
||||
if (task != null) {
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
}
|
||||
|
||||
if (json.charAt(json.length() - 1) != '{') {
|
||||
json.append(',');
|
||||
}
|
||||
// Begin hitting the server with glorious data
|
||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
private boolean firstPost = true;
|
||||
|
||||
if (isValueNumeric) {
|
||||
json.append(value);
|
||||
} else {
|
||||
json.append(escapeJSON(value));
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
try {
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a string to create a valid JSON string
|
||||
*
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private static String escapeJSON(String text) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
||||
// it is not a interval ping, so it evaluates to FALSE
|
||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
||||
postPlugin(!firstPost);
|
||||
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
char chr = text.charAt(index);
|
||||
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
builder.append(chr);
|
||||
break;
|
||||
case '\b':
|
||||
builder.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
builder.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
builder.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u" + t.substring(t.length() - 4));
|
||||
} else {
|
||||
builder.append(chr);
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (IOException e) {
|
||||
if (debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}, 0, PING_INTERVAL * 1200);
|
||||
|
||||
return true;
|
||||
}
|
||||
builder.append('"');
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
}
|
|
@ -13,106 +13,24 @@ import com.projectkorra.ProjectKorra.Ability.MultiAbility.MultiAbilityModule;
|
|||
import com.projectkorra.ProjectKorra.Ability.MultiAbility.MultiAbilityModuleManager;
|
||||
|
||||
public class MultiAbilityManager {
|
||||
|
||||
|
||||
public static ConcurrentHashMap<Player, HashMap<Integer, String>> playerAbilities = new ConcurrentHashMap<Player, HashMap<Integer, String>>();
|
||||
public static ConcurrentHashMap<Player, Integer> playerSlot = new ConcurrentHashMap<Player, Integer>();
|
||||
public static ConcurrentHashMap<Player, String> playerBoundAbility = new ConcurrentHashMap<Player, String>();
|
||||
public static ArrayList<MultiAbility> multiAbilityList = new ArrayList<MultiAbility>();
|
||||
|
||||
|
||||
public MultiAbilityManager() {
|
||||
ArrayList<MultiAbilitySub> waterArms = new ArrayList<MultiAbilitySub>();
|
||||
waterArms.add(new MultiAbilitySub("Pull", Element.Water, null));
|
||||
waterArms.add(new MultiAbilitySub("Punch", Element.Water, null));
|
||||
waterArms.add(new MultiAbilitySub("Grapple", Element.Water, null));
|
||||
waterArms.add(new MultiAbilitySub("Grab", Element.Water, null));
|
||||
waterArms.add(new MultiAbilitySub("Freeze", Element.Water,
|
||||
SubElement.Icebending));
|
||||
waterArms.add(new MultiAbilitySub("Spear", Element.Water,
|
||||
SubElement.Icebending));
|
||||
waterArms.add(new MultiAbilitySub("Freeze", Element.Water, SubElement.Icebending));
|
||||
waterArms.add(new MultiAbilitySub("Spear", Element.Water, SubElement.Icebending));
|
||||
multiAbilityList.add(new MultiAbility("WaterArms", waterArms));
|
||||
manage();
|
||||
}
|
||||
|
||||
/**
|
||||
* MultiAbility class. Manages each MultiAbility's sub abilities.
|
||||
*
|
||||
*/
|
||||
public static class MultiAbility {
|
||||
private String name;
|
||||
private ArrayList<MultiAbilitySub> abilities;
|
||||
|
||||
public MultiAbility(String name, ArrayList<MultiAbilitySub> abilities) {
|
||||
this.name = name;
|
||||
this.abilities = abilities;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ArrayList<MultiAbilitySub> getAbilities() {
|
||||
return abilities;
|
||||
}
|
||||
|
||||
public void setAbilities(ArrayList<MultiAbilitySub> abilities) {
|
||||
this.abilities = abilities;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MultiAbilitySub {
|
||||
private String name;
|
||||
private Element element;
|
||||
private SubElement sub;
|
||||
|
||||
public MultiAbilitySub(String name, Element element, SubElement sub) {
|
||||
this.name = name;
|
||||
this.element = element;
|
||||
this.sub = sub;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public void setElement(Element element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public SubElement getSubElement() {
|
||||
return sub;
|
||||
}
|
||||
|
||||
public void setSubElement(SubElement sub) {
|
||||
this.sub = sub;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a MultiAbility based on name.
|
||||
*
|
||||
* @param multiAbility
|
||||
* @return
|
||||
*/
|
||||
public static MultiAbility getMultiAbility(String multiAbility) {
|
||||
for (MultiAbility ma : multiAbilityList) {
|
||||
if (ma.getName().equalsIgnoreCase(multiAbility))
|
||||
return ma;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a player's binds for a MultiAbility.
|
||||
*
|
||||
|
@ -160,6 +78,124 @@ public class MultiAbilityManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MultiAbility the player has bound. Returns null if no
|
||||
* multiability is bound and active.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public static String getBoundMultiAbility(Player player) {
|
||||
if (playerBoundAbility.containsKey(player))
|
||||
return playerBoundAbility.get(player);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a MultiAbility based on name.
|
||||
*
|
||||
* @param multiAbility
|
||||
* @return
|
||||
*/
|
||||
public static MultiAbility getMultiAbility(String multiAbility) {
|
||||
for (MultiAbility ma : multiAbilityList) {
|
||||
if (ma.getName().equalsIgnoreCase(multiAbility))
|
||||
return ma;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean based on whether a player has a MultiAbility active.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasMultiAbilityBound(Player player) {
|
||||
if (playerAbilities.containsKey(player))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* MultiAbility equivalent of GeneralMethods.getBoundAbility(). Returns a
|
||||
* boolean based on whether a player has a specific MultiAbility active.
|
||||
*
|
||||
* @param player
|
||||
* @param multiAbility
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasMultiAbilityBound(Player player,
|
||||
String multiAbility) {
|
||||
if (playerAbilities.containsKey(player)) {
|
||||
if (!playerBoundAbility.get(player).equals(multiAbility)
|
||||
&& GeneralMethods.getBoundAbility(player) != null)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void manage() {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
scrollHotBarSlots();
|
||||
}
|
||||
}.runTaskTimer(ProjectKorra.plugin, 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all MultiAbility data for a player. Called on player quit event.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void remove(Player player) {
|
||||
playerAbilities.remove(player);
|
||||
playerBoundAbility.remove(player);
|
||||
playerSlot.remove(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up all MultiAbilities.
|
||||
*/
|
||||
public static void removeAll() {
|
||||
List<MultiAbilityModule> abilities = MultiAbilityModuleManager.multiAbility;
|
||||
for (MultiAbilityModule mam : abilities)
|
||||
mam.stop();
|
||||
|
||||
playerAbilities.clear();
|
||||
playerSlot.clear();
|
||||
playerBoundAbility.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps track of the player's selected slot while a MultiAbility is active.
|
||||
*/
|
||||
public static void scrollHotBarSlots() {
|
||||
if (!playerAbilities.isEmpty()) {
|
||||
for (Player player : playerAbilities.keySet()) {
|
||||
if (playerBoundAbility.containsKey(player)) {
|
||||
if (GeneralMethods.getBoundAbility(player) == null) {
|
||||
if (multiAbilityList
|
||||
.contains(getMultiAbility(playerBoundAbility
|
||||
.get(player)))) {
|
||||
if (player.getInventory().getHeldItemSlot() > getMultiAbility(
|
||||
playerBoundAbility.get(player))
|
||||
.getAbilities().size()) {
|
||||
player.getInventory().setHeldItemSlot(
|
||||
getMultiAbility(
|
||||
playerBoundAbility.get(player))
|
||||
.getAbilities().size() - 1);
|
||||
} else {
|
||||
player.getInventory().setHeldItemSlot(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts a player's binds to a previous state before use of a
|
||||
* MultiAbility.
|
||||
|
@ -199,108 +235,71 @@ public class MultiAbilityManager {
|
|||
if (playerBoundAbility.containsKey(player))
|
||||
playerBoundAbility.remove(player);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MultiAbility equivalent of GeneralMethods.getBoundAbility(). Returns a
|
||||
* boolean based on whether a player has a specific MultiAbility active.
|
||||
*
|
||||
* @param player
|
||||
* @param multiAbility
|
||||
* @return
|
||||
* MultiAbility class. Manages each MultiAbility's sub abilities.
|
||||
*
|
||||
*/
|
||||
public static boolean hasMultiAbilityBound(Player player,
|
||||
String multiAbility) {
|
||||
if (playerAbilities.containsKey(player)) {
|
||||
if (!playerBoundAbility.get(player).equals(multiAbility)
|
||||
&& GeneralMethods.getBoundAbility(player) != null)
|
||||
return false;
|
||||
return true;
|
||||
public static class MultiAbility {
|
||||
private String name;
|
||||
private ArrayList<MultiAbilitySub> abilities;
|
||||
|
||||
public MultiAbility(String name, ArrayList<MultiAbilitySub> abilities) {
|
||||
this.name = name;
|
||||
this.abilities = abilities;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean based on whether a player has a MultiAbility active.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasMultiAbilityBound(Player player) {
|
||||
if (playerAbilities.containsKey(player))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public ArrayList<MultiAbilitySub> getAbilities() {
|
||||
return abilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MultiAbility the player has bound. Returns null if no
|
||||
* multiability is bound and active.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public static String getBoundMultiAbility(Player player) {
|
||||
if (playerBoundAbility.containsKey(player))
|
||||
return playerBoundAbility.get(player);
|
||||
return null;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static void manage() {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
scrollHotBarSlots();
|
||||
}
|
||||
}.runTaskTimer(ProjectKorra.plugin, 0, 1);
|
||||
}
|
||||
public void setAbilities(ArrayList<MultiAbilitySub> abilities) {
|
||||
this.abilities = abilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps track of the player's selected slot while a MultiAbility is active.
|
||||
*/
|
||||
public static void scrollHotBarSlots() {
|
||||
if (!playerAbilities.isEmpty()) {
|
||||
for (Player player : playerAbilities.keySet()) {
|
||||
if (playerBoundAbility.containsKey(player)) {
|
||||
if (GeneralMethods.getBoundAbility(player) == null) {
|
||||
if (multiAbilityList
|
||||
.contains(getMultiAbility(playerBoundAbility
|
||||
.get(player)))) {
|
||||
if (player.getInventory().getHeldItemSlot() > getMultiAbility(
|
||||
playerBoundAbility.get(player))
|
||||
.getAbilities().size()) {
|
||||
player.getInventory().setHeldItemSlot(
|
||||
getMultiAbility(
|
||||
playerBoundAbility.get(player))
|
||||
.getAbilities().size() - 1);
|
||||
} else {
|
||||
player.getInventory().setHeldItemSlot(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MultiAbilitySub {
|
||||
private String name;
|
||||
private Element element;
|
||||
private SubElement sub;
|
||||
|
||||
public MultiAbilitySub(String name, Element element, SubElement sub) {
|
||||
this.name = name;
|
||||
this.element = element;
|
||||
this.sub = sub;
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SubElement getSubElement() {
|
||||
return sub;
|
||||
}
|
||||
|
||||
public void setElement(Element element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setSubElement(SubElement sub) {
|
||||
this.sub = sub;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all MultiAbility data for a player. Called on player quit event.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void remove(Player player) {
|
||||
playerAbilities.remove(player);
|
||||
playerBoundAbility.remove(player);
|
||||
playerSlot.remove(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up all MultiAbilities.
|
||||
*/
|
||||
public static void removeAll() {
|
||||
List<MultiAbilityModule> abilities = MultiAbilityModuleManager.multiAbility;
|
||||
for (MultiAbilityModule mam : abilities)
|
||||
mam.stop();
|
||||
|
||||
playerAbilities.clear();
|
||||
playerSlot.clear();
|
||||
playerBoundAbility.clear();
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,6 @@ package com.projectkorra.ProjectKorra;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -27,14 +26,15 @@ import com.projectkorra.ProjectKorra.waterbending.WaterbendingManager;
|
|||
|
||||
public class ProjectKorra extends JavaPlugin {
|
||||
|
||||
public static long time_step = 1;
|
||||
public static ProjectKorra plugin;
|
||||
public static Logger log;
|
||||
public static PKLogHandler handler;
|
||||
public static long time_step = 1;
|
||||
public Updater updater;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
ProjectKorra.log = this.getLogger();
|
||||
try {
|
||||
handler = new PKLogHandler(getDataFolder() + File.separator + "ERROR.log");
|
||||
|
@ -43,7 +43,6 @@ public class ProjectKorra extends JavaPlugin {
|
|||
} catch (SecurityException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
plugin = this;
|
||||
new ConfigManager(this);
|
||||
new GeneralMethods(this);
|
||||
updater = new Updater(this, "http://projectkorra.com/forum/forums/dev-builds.16/index.rss");
|
||||
|
@ -54,31 +53,32 @@ public class ProjectKorra extends JavaPlugin {
|
|||
new ComboModuleManager();
|
||||
new ComboManager();
|
||||
new ChiComboManager();
|
||||
new CraftingRecipes(this);
|
||||
|
||||
DBConnection.host = getConfig().getString("Storage.MySQL.host");
|
||||
DBConnection.port = getConfig().getInt("Storage.MySQL.port");
|
||||
DBConnection.pass = getConfig().getString("Storage.MySQL.pass");
|
||||
DBConnection.db = getConfig().getString("Storage.MySQL.db");
|
||||
DBConnection.user = getConfig().getString("Storage.MySQL.user");
|
||||
DBConnection.init();
|
||||
if (DBConnection.isOpen() == false) {
|
||||
//TODO: Log a proper message displaying database problem, pk will not function
|
||||
return;
|
||||
}
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PKListener(this), this);
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new BendingManager(this), 0, 1);
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new AirbendingManager(this), 0, 1);
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new WaterbendingManager(this), 0, 1);
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new EarthbendingManager(this), 0, 1);
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new FirebendingManager(this), 0, 1);
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1);
|
||||
|
||||
DBConnection.init();
|
||||
if (DBConnection.isOpen() == false) return;
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200);
|
||||
|
||||
for (Player player: Bukkit.getOnlinePlayers()) {
|
||||
GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName());
|
||||
Preset.loadPresets(player);
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(new PKListener(this), this);
|
||||
|
||||
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200);
|
||||
|
||||
try {
|
||||
MetricsLite metrics = new MetricsLite(this);
|
||||
|
@ -89,16 +89,15 @@ public class ProjectKorra extends JavaPlugin {
|
|||
|
||||
GeneralMethods.deserializeFile();
|
||||
GeneralMethods.startCacheCleaner(GeneralMethods.CACHE_TIME);
|
||||
new CraftingRecipes(this);
|
||||
|
||||
updater.checkUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
GeneralMethods.stopBending();
|
||||
if (DBConnection.isOpen == false) return;
|
||||
DBConnection.sql.close();
|
||||
if (DBConnection.isOpen != false) {
|
||||
DBConnection.sql.close();
|
||||
}
|
||||
handler.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,48 +16,53 @@ import com.projectkorra.ProjectKorra.earthbending.EarthMethods;
|
|||
|
||||
public class RevertChecker implements Runnable {
|
||||
|
||||
private ProjectKorra plugin;
|
||||
|
||||
private static final boolean safeRevert = ProjectKorra.plugin.getConfig().getBoolean("Properties.Earth.SafeRevert");
|
||||
public static ConcurrentHashMap<Block, Block> earthRevertQueue = new ConcurrentHashMap<Block, Block>();
|
||||
static ConcurrentHashMap<Integer, Integer> airRevertQueue = new ConcurrentHashMap<Integer, Integer>();
|
||||
private Future<ArrayList<Chunk>> returnFuture;
|
||||
static ConcurrentHashMap<Chunk, Chunk> chunks = new ConcurrentHashMap<Chunk, Chunk>();
|
||||
// static ConcurrentHashMap<Block, Material> movedEarthQueue = new
|
||||
// ConcurrentHashMap<Block, Material>();
|
||||
|
||||
static ConcurrentHashMap<Chunk, Chunk> chunks = new ConcurrentHashMap<Chunk, Chunk>();
|
||||
|
||||
private ProjectKorra plugin;
|
||||
|
||||
private static final boolean safeRevert = ProjectKorra.plugin.getConfig().getBoolean("Properties.Earth.SafeRevert");
|
||||
|
||||
private long time;
|
||||
|
||||
|
||||
public RevertChecker(ProjectKorra bending) {
|
||||
plugin = bending;
|
||||
}
|
||||
|
||||
private class getOccupiedChunks implements Callable<ArrayList<Chunk>> {
|
||||
|
||||
private Server server;
|
||||
|
||||
public getOccupiedChunks(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Chunk> call() throws Exception {
|
||||
|
||||
ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
||||
|
||||
for (Player player : server.getOnlinePlayers()) {
|
||||
Chunk chunk = player.getLocation().getChunk();
|
||||
if (!chunks.contains(chunk))
|
||||
chunks.add(chunk);
|
||||
}
|
||||
return chunks;
|
||||
|
||||
|
||||
public static void revertAirBlocks() {
|
||||
for (int ID : airRevertQueue.keySet()) {
|
||||
EarthMethods.revertAirBlock(ID);
|
||||
RevertChecker.airRevertQueue.remove(ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void revertEarthBlocks() {
|
||||
for (Block block : earthRevertQueue.keySet()) {
|
||||
EarthMethods.revertBlock(block);
|
||||
earthRevertQueue.remove(block);
|
||||
}
|
||||
}
|
||||
|
||||
private Future<ArrayList<Chunk>> returnFuture;
|
||||
// void addToMovedEarthQueue(Block block, Material type) {
|
||||
// if (!movedEarthQueue.containsKey(block))
|
||||
// movedEarthQueue.put(block, type);
|
||||
//
|
||||
// }
|
||||
|
||||
private void addToAirRevertQueue(int i) {
|
||||
if (!airRevertQueue.containsKey(i))
|
||||
airRevertQueue.put(i, i);
|
||||
|
||||
}
|
||||
|
||||
private void addToRevertQueue(Block block) {
|
||||
if (!earthRevertQueue.containsKey(block))
|
||||
earthRevertQueue.put(block, block);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
time = System.currentTimeMillis();
|
||||
|
@ -111,35 +116,26 @@ public class RevertChecker implements Runnable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class getOccupiedChunks implements Callable<ArrayList<Chunk>> {
|
||||
private Server server;
|
||||
|
||||
private void addToAirRevertQueue(int i) {
|
||||
if (!airRevertQueue.containsKey(i))
|
||||
airRevertQueue.put(i, i);
|
||||
|
||||
}
|
||||
|
||||
// void addToMovedEarthQueue(Block block, Material type) {
|
||||
// if (!movedEarthQueue.containsKey(block))
|
||||
// movedEarthQueue.put(block, type);
|
||||
//
|
||||
// }
|
||||
|
||||
void addToRevertQueue(Block block) {
|
||||
if (!earthRevertQueue.containsKey(block))
|
||||
earthRevertQueue.put(block, block);
|
||||
}
|
||||
|
||||
public static void revertEarthBlocks() {
|
||||
for (Block block : earthRevertQueue.keySet()) {
|
||||
EarthMethods.revertBlock(block);
|
||||
earthRevertQueue.remove(block);
|
||||
public getOccupiedChunks(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
}
|
||||
|
||||
public static void revertAirBlocks() {
|
||||
for (int ID : airRevertQueue.keySet()) {
|
||||
EarthMethods.revertAirBlock(ID);
|
||||
RevertChecker.airRevertQueue.remove(ID);
|
||||
@Override
|
||||
public ArrayList<Chunk> call() throws Exception {
|
||||
|
||||
ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
||||
|
||||
for (Player player : server.getOnlinePlayers()) {
|
||||
Chunk chunk = player.getLocation().getChunk();
|
||||
if (!chunks.contains(chunk))
|
||||
chunks.add(chunk);
|
||||
}
|
||||
return chunks;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,5 @@ public enum SubElement {
|
|||
if (index == -1) return null;
|
||||
return (SubElement)Arrays.asList(values()).get(index);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.projectkorra.ProjectKorra;
|
|||
import org.bukkit.event.Listener;
|
||||
//import org.kitteh.tag.AsyncPlayerReceiveNameTagEvent;
|
||||
|
||||
@Deprecated
|
||||
public class TagAPIListener implements Listener {
|
||||
|
||||
}
|
||||
|
|
|
@ -43,10 +43,37 @@ public class TempBlock {
|
|||
if (state.getType() == Material.FIRE)
|
||||
state.setType(Material.AIR);
|
||||
}
|
||||
|
||||
public static TempBlock get(Block block) {
|
||||
if (isTempBlock(block))
|
||||
return instances.get(block);
|
||||
return null;
|
||||
}
|
||||
public static boolean isTempBlock(Block block) {
|
||||
if (instances.containsKey(block))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public static boolean isTouchingTempBlock(Block block) {
|
||||
BlockFace[] faces = { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST,
|
||||
BlockFace.WEST, BlockFace.UP, BlockFace.DOWN };
|
||||
for (BlockFace face : faces) {
|
||||
if (instances.containsKey(block.getRelative(face)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static void removeAll() {
|
||||
for (Block block : instances.keySet()) {
|
||||
revertBlock(block, Material.AIR);
|
||||
}
|
||||
|
||||
public void revertBlock() {
|
||||
state.update(true);
|
||||
instances.remove(block);
|
||||
}
|
||||
|
||||
public static void removeBlock(Block block) {
|
||||
if (instances.containsKey(block)) {
|
||||
instances.remove(block);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -72,55 +99,25 @@ public class TempBlock {
|
|||
// block.setType(defaulttype);
|
||||
}
|
||||
|
||||
public static void removeBlock(Block block) {
|
||||
if (instances.containsKey(block)) {
|
||||
instances.remove(block);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isTempBlock(Block block) {
|
||||
if (instances.containsKey(block))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isTouchingTempBlock(Block block) {
|
||||
BlockFace[] faces = { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST,
|
||||
BlockFace.WEST, BlockFace.UP, BlockFace.DOWN };
|
||||
for (BlockFace face : faces) {
|
||||
if (instances.containsKey(block.getRelative(face)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static TempBlock get(Block block) {
|
||||
if (isTempBlock(block))
|
||||
return instances.get(block);
|
||||
return null;
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return block.getLocation();
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public BlockState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(BlockState newstate) {
|
||||
state = newstate;
|
||||
public void revertBlock() {
|
||||
state.update(true);
|
||||
instances.remove(block);
|
||||
}
|
||||
|
||||
public static void removeAll() {
|
||||
for (Block block : instances.keySet()) {
|
||||
revertBlock(block, Material.AIR);
|
||||
}
|
||||
|
||||
public void setState(BlockState newstate) {
|
||||
state = newstate;
|
||||
}
|
||||
|
||||
public void setType(Material material) {
|
||||
|
|
|
@ -8,14 +8,84 @@ import org.bukkit.potion.PotionEffect;
|
|||
public class TempPotionEffect {
|
||||
|
||||
private static ConcurrentHashMap<LivingEntity, TempPotionEffect> instances = new ConcurrentHashMap<LivingEntity, TempPotionEffect>();
|
||||
|
||||
private static final long tick = 21;
|
||||
|
||||
private int ID = Integer.MIN_VALUE;
|
||||
|
||||
private ConcurrentHashMap<Integer, PotionInfo> infos = new ConcurrentHashMap<Integer, PotionInfo>();
|
||||
private LivingEntity entity;
|
||||
|
||||
public TempPotionEffect(LivingEntity entity, PotionEffect effect) {
|
||||
this(entity, effect, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public TempPotionEffect(LivingEntity entity, PotionEffect effect, long starttime) {
|
||||
this.entity = entity;
|
||||
if (instances.containsKey(entity)) {
|
||||
TempPotionEffect instance = instances.get(entity);
|
||||
instance.infos.put(instance.ID++, new PotionInfo(starttime, effect));
|
||||
// instance.effects.put(starttime, effect);
|
||||
instances.replace(entity, instance);
|
||||
} else {
|
||||
// effects.put(starttime, effect);
|
||||
infos.put(ID++, new PotionInfo(starttime, effect));
|
||||
instances.put(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void progressAll() {
|
||||
for (LivingEntity entity : instances.keySet()) {
|
||||
if (instances.get(entity) == null) continue;
|
||||
instances.get(entity).progress();
|
||||
}
|
||||
}
|
||||
|
||||
private void addEffect(PotionEffect effect) {
|
||||
for (PotionEffect peffect : entity.getActivePotionEffects()) {
|
||||
if (peffect.getType().equals(effect.getType())) {
|
||||
if (peffect.getAmplifier() > effect.getAmplifier()) {
|
||||
if (peffect.getDuration() > effect.getDuration()) {
|
||||
return;
|
||||
} else {
|
||||
int dt = effect.getDuration() - peffect.getDuration();
|
||||
PotionEffect neweffect = new PotionEffect( effect.getType(), dt, effect.getAmplifier());
|
||||
new TempPotionEffect(entity, neweffect,
|
||||
System.currentTimeMillis() + peffect.getDuration() * tick);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (peffect.getDuration() > effect.getDuration()) {
|
||||
entity.removePotionEffect(peffect.getType());
|
||||
entity.addPotionEffect(effect);
|
||||
int dt = peffect.getDuration() - effect.getDuration();
|
||||
PotionEffect neweffect = new PotionEffect(
|
||||
peffect.getType(), dt, peffect.getAmplifier());
|
||||
new TempPotionEffect(entity, neweffect,
|
||||
System.currentTimeMillis()
|
||||
+ effect.getDuration() * tick);
|
||||
return;
|
||||
} else {
|
||||
entity.removePotionEffect(peffect.getType());
|
||||
entity.addPotionEffect(effect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
entity.addPotionEffect(effect);
|
||||
}
|
||||
|
||||
private void progress() {
|
||||
for (int id : infos.keySet()) {
|
||||
PotionInfo info = infos.get(id);
|
||||
if (info.getTime() < System.currentTimeMillis()) {
|
||||
addEffect(info.getEffect());
|
||||
infos.remove(id);
|
||||
}
|
||||
}
|
||||
if (infos.isEmpty() && instances.containsKey(entity))
|
||||
instances.remove(entity);
|
||||
}
|
||||
|
||||
private class PotionInfo {
|
||||
|
||||
private long starttime;
|
||||
|
@ -36,84 +106,4 @@ public class TempPotionEffect {
|
|||
|
||||
}
|
||||
|
||||
public TempPotionEffect(LivingEntity entity, PotionEffect effect,
|
||||
long starttime) {
|
||||
this.entity = entity;
|
||||
if (instances.containsKey(entity)) {
|
||||
TempPotionEffect instance = instances.get(entity);
|
||||
instance.infos
|
||||
.put(instance.ID++, new PotionInfo(starttime, effect));
|
||||
// instance.effects.put(starttime, effect);
|
||||
instances.replace(entity, instance);
|
||||
} else {
|
||||
// effects.put(starttime, effect);
|
||||
infos.put(ID++, new PotionInfo(starttime, effect));
|
||||
instances.put(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
public TempPotionEffect(LivingEntity entity, PotionEffect effect) {
|
||||
this(entity, effect, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private void addEffect(PotionEffect effect) {
|
||||
for (PotionEffect peffect : entity.getActivePotionEffects()) {
|
||||
if (peffect.getType().equals(effect.getType())) {
|
||||
if (peffect.getAmplifier() > effect.getAmplifier()) {
|
||||
|
||||
if (peffect.getDuration() > effect.getDuration()) {
|
||||
return;
|
||||
} else {
|
||||
int dt = effect.getDuration() - peffect.getDuration();
|
||||
PotionEffect neweffect = new PotionEffect(
|
||||
effect.getType(), dt, effect.getAmplifier());
|
||||
new TempPotionEffect(entity, neweffect,
|
||||
System.currentTimeMillis()
|
||||
+ peffect.getDuration() * tick);
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (peffect.getDuration() > effect.getDuration()) {
|
||||
entity.removePotionEffect(peffect.getType());
|
||||
entity.addPotionEffect(effect);
|
||||
int dt = peffect.getDuration() - effect.getDuration();
|
||||
PotionEffect neweffect = new PotionEffect(
|
||||
peffect.getType(), dt, peffect.getAmplifier());
|
||||
new TempPotionEffect(entity, neweffect,
|
||||
System.currentTimeMillis()
|
||||
+ effect.getDuration() * tick);
|
||||
return;
|
||||
} else {
|
||||
entity.removePotionEffect(peffect.getType());
|
||||
entity.addPotionEffect(effect);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
entity.addPotionEffect(effect);
|
||||
}
|
||||
|
||||
private void progress() {
|
||||
for (int id : infos.keySet()) {
|
||||
PotionInfo info = infos.get(id);
|
||||
if (info.getTime() < System.currentTimeMillis()) {
|
||||
addEffect(info.getEffect());
|
||||
infos.remove(id);
|
||||
}
|
||||
}
|
||||
if (infos.isEmpty() && instances.containsKey(entity))
|
||||
instances.remove(entity);
|
||||
}
|
||||
|
||||
public static void progressAll() {
|
||||
for (LivingEntity entity : instances.keySet()) {
|
||||
if (instances.get(entity) == null) continue;
|
||||
instances.get(entity).progress();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue