Check System Added and Massive Reformat
This commit is contained in:
@@ -7,104 +7,104 @@ import java.util.ArrayList;
|
||||
|
||||
public class AsciiCompass {
|
||||
|
||||
public static Point getCompassPointForDirection(double inDegrees) {
|
||||
double degrees = (inDegrees - 180) % 360;
|
||||
if (degrees < 0) {
|
||||
degrees += 360;
|
||||
}
|
||||
public static Point getCompassPointForDirection(double inDegrees) {
|
||||
double degrees = (inDegrees - 180) % 360;
|
||||
if (degrees < 0) {
|
||||
degrees += 360;
|
||||
}
|
||||
|
||||
if (0 <= degrees && degrees < 22.5) {
|
||||
return Point.N;
|
||||
} else if (22.5 <= degrees && degrees < 67.5) {
|
||||
return Point.NE;
|
||||
} else if (67.5 <= degrees && degrees < 112.5) {
|
||||
return Point.E;
|
||||
} else if (112.5 <= degrees && degrees < 157.5) {
|
||||
return Point.SE;
|
||||
} else if (157.5 <= degrees && degrees < 202.5) {
|
||||
return Point.S;
|
||||
} else if (202.5 <= degrees && degrees < 247.5) {
|
||||
return Point.SW;
|
||||
} else if (247.5 <= degrees && degrees < 292.5) {
|
||||
return Point.W;
|
||||
} else if (292.5 <= degrees && degrees < 337.5) {
|
||||
return Point.NW;
|
||||
} else if (337.5 <= degrees && degrees < 360.0) {
|
||||
return Point.N;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (0 <= degrees && degrees < 22.5) {
|
||||
return Point.N;
|
||||
} else if (22.5 <= degrees && degrees < 67.5) {
|
||||
return Point.NE;
|
||||
} else if (67.5 <= degrees && degrees < 112.5) {
|
||||
return Point.E;
|
||||
} else if (112.5 <= degrees && degrees < 157.5) {
|
||||
return Point.SE;
|
||||
} else if (157.5 <= degrees && degrees < 202.5) {
|
||||
return Point.S;
|
||||
} else if (202.5 <= degrees && degrees < 247.5) {
|
||||
return Point.SW;
|
||||
} else if (247.5 <= degrees && degrees < 292.5) {
|
||||
return Point.W;
|
||||
} else if (292.5 <= degrees && degrees < 337.5) {
|
||||
return Point.NW;
|
||||
} else if (337.5 <= degrees && degrees < 360.0) {
|
||||
return Point.N;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) {
|
||||
ArrayList<String> ret = new ArrayList<>();
|
||||
String row;
|
||||
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) {
|
||||
ArrayList<String> ret = new ArrayList<>();
|
||||
String row;
|
||||
|
||||
row = "";
|
||||
row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
|
||||
row += Point.N.toString(Point.N == point, colorActive, colorDefault);
|
||||
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
row = "";
|
||||
row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
|
||||
row += Point.N.toString(Point.N == point, colorActive, colorDefault);
|
||||
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
|
||||
row = "";
|
||||
row += Point.W.toString(Point.W == point, colorActive, colorDefault);
|
||||
row += colorDefault + "+";
|
||||
row += Point.E.toString(Point.E == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
row = "";
|
||||
row += Point.W.toString(Point.W == point, colorActive, colorDefault);
|
||||
row += colorDefault + "+";
|
||||
row += Point.E.toString(Point.E == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
|
||||
row = "";
|
||||
row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
|
||||
row += Point.S.toString(Point.S == point, colorActive, colorDefault);
|
||||
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
row = "";
|
||||
row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
|
||||
row += Point.S.toString(Point.S == point, colorActive, colorDefault);
|
||||
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getAsciiCompass(double inDegrees, ChatColor colorActive, String colorDefault) {
|
||||
return getAsciiCompass(getCompassPointForDirection(inDegrees), colorActive, colorDefault);
|
||||
}
|
||||
public static ArrayList<String> getAsciiCompass(double inDegrees, ChatColor colorActive, String colorDefault) {
|
||||
return getAsciiCompass(getCompassPointForDirection(inDegrees), colorActive, colorDefault);
|
||||
}
|
||||
|
||||
public enum Point {
|
||||
public enum Point {
|
||||
|
||||
N('N'),
|
||||
NE('/'),
|
||||
E('E'),
|
||||
SE('\\'),
|
||||
S('S'),
|
||||
SW('/'),
|
||||
W('W'),
|
||||
NW('\\');
|
||||
N('N'),
|
||||
NE('/'),
|
||||
E('E'),
|
||||
SE('\\'),
|
||||
S('S'),
|
||||
SW('/'),
|
||||
W('W'),
|
||||
NW('\\');
|
||||
|
||||
public final char asciiChar;
|
||||
public final char asciiChar;
|
||||
|
||||
Point(final char asciiChar) {
|
||||
this.asciiChar = asciiChar;
|
||||
}
|
||||
Point(final char asciiChar) {
|
||||
this.asciiChar = asciiChar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(this.asciiChar);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(this.asciiChar);
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
if (this == N) {
|
||||
return TL.COMPASS_SHORT_NORTH.toString();
|
||||
}
|
||||
if (this == E) {
|
||||
return TL.COMPASS_SHORT_EAST.toString();
|
||||
}
|
||||
if (this == S) {
|
||||
return TL.COMPASS_SHORT_SOUTH.toString();
|
||||
}
|
||||
if (this == W) {
|
||||
return TL.COMPASS_SHORT_WEST.toString();
|
||||
}
|
||||
return toString();
|
||||
}
|
||||
public String getTranslation() {
|
||||
if (this == N) {
|
||||
return TL.COMPASS_SHORT_NORTH.toString();
|
||||
}
|
||||
if (this == E) {
|
||||
return TL.COMPASS_SHORT_EAST.toString();
|
||||
}
|
||||
if (this == S) {
|
||||
return TL.COMPASS_SHORT_SOUTH.toString();
|
||||
}
|
||||
if (this == W) {
|
||||
return TL.COMPASS_SHORT_WEST.toString();
|
||||
}
|
||||
return toString();
|
||||
}
|
||||
|
||||
public String toString(boolean isActive, ChatColor colorActive, String colorDefault) {
|
||||
return (isActive ? colorActive : colorDefault) + getTranslation();
|
||||
}
|
||||
}
|
||||
public String toString(boolean isActive, ChatColor colorActive, String colorDefault) {
|
||||
return (isActive ? colorActive : colorDefault) + getTranslation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,84 +10,84 @@ import java.util.logging.Level;
|
||||
|
||||
public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
|
||||
private transient boolean readyToGo = false;
|
||||
private transient boolean finished = false;
|
||||
private transient ListIterator<FPlayer> iterator;
|
||||
private transient double toleranceMillis;
|
||||
private transient boolean readyToGo = false;
|
||||
private transient boolean finished = false;
|
||||
private transient ListIterator<FPlayer> iterator;
|
||||
private transient double toleranceMillis;
|
||||
|
||||
public AutoLeaveProcessTask() {
|
||||
ArrayList<FPlayer> fplayers = (ArrayList<FPlayer>) FPlayers.getInstance().getAllFPlayers();
|
||||
this.iterator = fplayers.listIterator();
|
||||
this.toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
|
||||
this.readyToGo = true;
|
||||
this.finished = false;
|
||||
}
|
||||
public AutoLeaveProcessTask() {
|
||||
ArrayList<FPlayer> fplayers = (ArrayList<FPlayer>) FPlayers.getInstance().getAllFPlayers();
|
||||
this.iterator = fplayers.listIterator();
|
||||
this.toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
|
||||
this.readyToGo = true;
|
||||
this.finished = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (Conf.autoLeaveAfterDaysOfInactivity <= 0.0 || Conf.autoLeaveRoutineMaxMillisecondsPerTick <= 0.0) {
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
public void run() {
|
||||
if (Conf.autoLeaveAfterDaysOfInactivity <= 0.0 || Conf.autoLeaveRoutineMaxMillisecondsPerTick <= 0.0) {
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!readyToGo) {
|
||||
return;
|
||||
}
|
||||
// this is set so it only does one iteration at a time, no matter how frequently the timer fires
|
||||
readyToGo = false;
|
||||
// and this is tracked to keep one iteration from dragging on too long and possibly choking the system if there are a very large number of players to go through
|
||||
long loopStartTime = System.currentTimeMillis();
|
||||
if (!readyToGo) {
|
||||
return;
|
||||
}
|
||||
// this is set so it only does one iteration at a time, no matter how frequently the timer fires
|
||||
readyToGo = false;
|
||||
// and this is tracked to keep one iteration from dragging on too long and possibly choking the system if there are a very large number of players to go through
|
||||
long loopStartTime = System.currentTimeMillis();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
long now = System.currentTimeMillis();
|
||||
while (iterator.hasNext()) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
// if this iteration has been running for maximum time, stop to take a breather until next tick
|
||||
if (now > loopStartTime + Conf.autoLeaveRoutineMaxMillisecondsPerTick) {
|
||||
readyToGo = true;
|
||||
return;
|
||||
}
|
||||
// if this iteration has been running for maximum time, stop to take a breather until next tick
|
||||
if (now > loopStartTime + Conf.autoLeaveRoutineMaxMillisecondsPerTick) {
|
||||
readyToGo = true;
|
||||
return;
|
||||
}
|
||||
|
||||
FPlayer fplayer = iterator.next();
|
||||
FPlayer fplayer = iterator.next();
|
||||
|
||||
// Check if they should be exempt from this.
|
||||
if (!fplayer.willAutoLeave()) {
|
||||
P.p.debug(Level.INFO, fplayer.getName() + " was going to be auto-removed but was set not to.");
|
||||
continue;
|
||||
}
|
||||
// Check if they should be exempt from this.
|
||||
if (!fplayer.willAutoLeave()) {
|
||||
P.p.debug(Level.INFO, fplayer.getName() + " was going to be auto-removed but was set not to.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis) {
|
||||
if (Conf.logFactionLeave || Conf.logFactionKick) {
|
||||
P.p.log("Player " + fplayer.getName() + " was auto-removed due to inactivity.");
|
||||
}
|
||||
if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis) {
|
||||
if (Conf.logFactionLeave || Conf.logFactionKick) {
|
||||
P.p.log("Player " + fplayer.getName() + " was auto-removed due to inactivity.");
|
||||
}
|
||||
|
||||
// if player is faction admin, sort out the faction since he's going away
|
||||
if (fplayer.getRole() == Role.LEADER) {
|
||||
Faction faction = fplayer.getFaction();
|
||||
if (faction != null) {
|
||||
fplayer.getFaction().promoteNewLeader(true);
|
||||
}
|
||||
}
|
||||
// if player is faction admin, sort out the faction since he's going away
|
||||
if (fplayer.getRole() == Role.LEADER) {
|
||||
Faction faction = fplayer.getFaction();
|
||||
if (faction != null) {
|
||||
fplayer.getFaction().promoteNewLeader(true);
|
||||
}
|
||||
}
|
||||
|
||||
fplayer.leave(false);
|
||||
iterator.remove(); // go ahead and remove this list's link to the FPlayer object
|
||||
if (Conf.autoLeaveDeleteFPlayerData) {
|
||||
fplayer.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
fplayer.leave(false);
|
||||
iterator.remove(); // go ahead and remove this list's link to the FPlayer object
|
||||
if (Conf.autoLeaveDeleteFPlayerData) {
|
||||
fplayer.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// looks like we've finished
|
||||
this.stop();
|
||||
}
|
||||
// looks like we've finished
|
||||
this.stop();
|
||||
}
|
||||
|
||||
// we're done, shut down
|
||||
public void stop() {
|
||||
readyToGo = false;
|
||||
finished = true;
|
||||
// we're done, shut down
|
||||
public void stop() {
|
||||
readyToGo = false;
|
||||
finished = true;
|
||||
|
||||
this.cancel();
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,24 +5,24 @@ import com.massivecraft.factions.P;
|
||||
|
||||
public class AutoLeaveTask implements Runnable {
|
||||
|
||||
private static AutoLeaveProcessTask task;
|
||||
double rate;
|
||||
private static AutoLeaveProcessTask task;
|
||||
double rate;
|
||||
|
||||
public AutoLeaveTask() {
|
||||
this.rate = Conf.autoLeaveRoutineRunsEveryXMinutes;
|
||||
}
|
||||
public AutoLeaveTask() {
|
||||
this.rate = Conf.autoLeaveRoutineRunsEveryXMinutes;
|
||||
}
|
||||
|
||||
public synchronized void run() {
|
||||
if (task != null && !task.isFinished()) {
|
||||
return;
|
||||
}
|
||||
public synchronized void run() {
|
||||
if (task != null && !task.isFinished()) {
|
||||
return;
|
||||
}
|
||||
|
||||
task = new AutoLeaveProcessTask();
|
||||
task.runTaskTimer(P.p, 1, 1);
|
||||
task = new AutoLeaveProcessTask();
|
||||
task.runTaskTimer(P.p, 1, 1);
|
||||
|
||||
// maybe setting has been changed? if so, restart this task at new rate
|
||||
if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) {
|
||||
P.p.startAutoLeaveTask(true);
|
||||
}
|
||||
}
|
||||
// maybe setting has been changed? if so, restart this task at new rate
|
||||
if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) {
|
||||
P.p.startAutoLeaveTask(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.massivecraft.factions.util;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class CheckWallTask extends BukkitRunnable {
|
||||
|
||||
private int overtime;
|
||||
|
||||
public CheckWallTask() {
|
||||
overtime = 0;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
++overtime;
|
||||
for (Faction faction : Factions.getInstance().getAllFactions()) {
|
||||
if (faction.getCheckNotifier() != 0L && overtime % faction.getCheckNotifier() == 0L) {
|
||||
faction.sendCheckNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,161 +15,161 @@ import java.util.UUID;
|
||||
|
||||
public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements Relational {
|
||||
|
||||
// Identifier for this expansion
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "factionsuuid";
|
||||
}
|
||||
// Identifier for this expansion
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "factionsuuid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "drtshock";
|
||||
}
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "drtshock";
|
||||
}
|
||||
|
||||
// Since we are registering this expansion from the dependency, this can be null
|
||||
@Override
|
||||
public String getPlugin() {
|
||||
return null;
|
||||
}
|
||||
// Since we are registering this expansion from the dependency, this can be null
|
||||
@Override
|
||||
public String getPlugin() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return the plugin version since this expansion is bundled with the dependency
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return P.p.getDescription().getVersion();
|
||||
}
|
||||
// Return the plugin version since this expansion is bundled with the dependency
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return P.p.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Relational placeholders
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player p1, Player p2, String placeholder) {
|
||||
if (p1 == null || p2 == null || placeholder == null) {
|
||||
return "";
|
||||
}
|
||||
// Relational placeholders
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player p1, Player p2, String placeholder) {
|
||||
if (p1 == null || p2 == null || placeholder == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
FPlayer fp1 = FPlayers.getInstance().getByPlayer(p1);
|
||||
FPlayer fp2 = FPlayers.getInstance().getByPlayer(p2);
|
||||
if (fp1 == null || fp2 == null) {
|
||||
return "";
|
||||
}
|
||||
FPlayer fp1 = FPlayers.getInstance().getByPlayer(p1);
|
||||
FPlayer fp2 = FPlayers.getInstance().getByPlayer(p2);
|
||||
if (fp1 == null || fp2 == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
switch (placeholder) {
|
||||
case "relation":
|
||||
String relationName = fp1.getRelationTo(fp2).nicename;
|
||||
return relationName != null ? relationName : "";
|
||||
case "relation_color":
|
||||
ChatColor color = fp1.getColorTo(fp2);
|
||||
return color != null ? color.toString() : "";
|
||||
}
|
||||
switch (placeholder) {
|
||||
case "relation":
|
||||
String relationName = fp1.getRelationTo(fp2).nicename;
|
||||
return relationName != null ? relationName : "";
|
||||
case "relation_color":
|
||||
ChatColor color = fp1.getColorTo(fp2);
|
||||
return color != null ? color.toString() : "";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, String placeholder) {
|
||||
if (player == null || placeholder == null) {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, String placeholder) {
|
||||
if (player == null || placeholder == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
||||
Faction faction = fPlayer.getFaction();
|
||||
switch (placeholder) {
|
||||
// First list player stuff
|
||||
case "player_name":
|
||||
return fPlayer.getName();
|
||||
case "player_lastseen":
|
||||
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fPlayer.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
|
||||
return fPlayer.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fPlayer.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
|
||||
case "player_group":
|
||||
return P.p.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fPlayer.getId())));
|
||||
case "player_balance":
|
||||
return Econ.isSetup() ? Econ.getFriendlyBalance(fPlayer) : TL.ECON_OFF.format("balance");
|
||||
case "player_power":
|
||||
return String.valueOf(fPlayer.getPowerRounded());
|
||||
case "player_maxpower":
|
||||
return String.valueOf(fPlayer.getPowerMaxRounded());
|
||||
case "player_kills":
|
||||
return String.valueOf(fPlayer.getKills());
|
||||
case "player_deaths":
|
||||
return String.valueOf(fPlayer.getDeaths());
|
||||
case "player_role_prefix":
|
||||
return String.valueOf(fPlayer.getRolePrefix());
|
||||
case "player_role":
|
||||
return fPlayer.hasFaction() ? fPlayer.getRole().getPrefix() : "";
|
||||
case "player_role_name":
|
||||
return fPlayer.hasFaction() ? fPlayer.getRole().getTranslation().toString() : TL.PLACEHOLDER_ROLE_NAME.toString();
|
||||
// Then Faction stuff
|
||||
case "faction_name":
|
||||
return fPlayer.hasFaction() ? faction.getTag() : TL.NOFACTION_PREFIX.toString();
|
||||
case "faction_power":
|
||||
return String.valueOf(faction.getPowerRounded());
|
||||
case "faction_powermax":
|
||||
return String.valueOf(faction.getPowerMaxRounded());
|
||||
case "faction_description":
|
||||
return faction.getDescription();
|
||||
case "faction_claims":
|
||||
return String.valueOf(faction.getAllClaims().size());
|
||||
case "faction_founded":
|
||||
return TL.sdf.format(faction.getFoundedDate());
|
||||
case "faction_joining":
|
||||
return (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString());
|
||||
case "faction_peaceful":
|
||||
return faction.isPeaceful() ? Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString() : "";
|
||||
case "faction_tntbank_balance":
|
||||
return String.valueOf(faction.getTnt());
|
||||
case "faction_powerboost":
|
||||
double powerBoost = faction.getPowerBoost();
|
||||
return (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString()) + powerBoost + ")";
|
||||
case "faction_leader":
|
||||
FPlayer fAdmin = faction.getFPlayerAdmin();
|
||||
return fAdmin == null ? "Server" : fAdmin.getName().substring(0, fAdmin.getName().length() > 14 ? 13 : fAdmin.getName().length());
|
||||
case "faction_warps":
|
||||
return String.valueOf(faction.getWarps().size());
|
||||
case "faction_raidable":
|
||||
boolean raid = P.p.getConfig().getBoolean("hcf.raidable", false) && faction.getLandRounded() >= faction.getPowerRounded();
|
||||
return raid ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString();
|
||||
case "faction_home_world":
|
||||
return faction.hasHome() ? faction.getHome().getWorld().getName() : "";
|
||||
case "faction_home_x":
|
||||
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockX()) : "";
|
||||
case "faction_home_y":
|
||||
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockY()) : "";
|
||||
case "faction_home_z":
|
||||
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockZ()) : "";
|
||||
case "facion_land_value":
|
||||
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(faction.getLandRounded())) : TL.ECON_OFF.format("value");
|
||||
case "faction_land_refund":
|
||||
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(faction.getLandRounded())) : TL.ECON_OFF.format("refund");
|
||||
case "faction_bank_balance":
|
||||
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.getBalance(faction.getAccountId())) : TL.ECON_OFF.format("balance");
|
||||
case "faction_allies":
|
||||
return String.valueOf(faction.getRelationCount(Relation.ALLY));
|
||||
case "faction_enemies":
|
||||
return String.valueOf(faction.getRelationCount(Relation.ENEMY));
|
||||
case "faction_truces":
|
||||
return String.valueOf(faction.getRelationCount(Relation.TRUCE));
|
||||
case "faction_online":
|
||||
return String.valueOf(faction.getOnlinePlayers().size());
|
||||
case "faction_offline":
|
||||
return String.valueOf(faction.getFPlayers().size() - faction.getOnlinePlayers().size());
|
||||
case "faction_size":
|
||||
return String.valueOf(faction.getFPlayers().size());
|
||||
case "faction_kills":
|
||||
return String.valueOf(faction.getKills());
|
||||
case "faction_deaths":
|
||||
return String.valueOf(faction.getDeaths());
|
||||
case "faction_maxvaults":
|
||||
return String.valueOf(faction.getMaxVaults());
|
||||
case "faction_grace":
|
||||
return String.valueOf(Conf.gracePeriod);
|
||||
case "faction_name_at_location":
|
||||
Faction factionAtLocation = Board.getInstance().getFactionAt(new FLocation(player.getLocation()));
|
||||
return factionAtLocation != null ? factionAtLocation.getTag() : Factions.getInstance().getWilderness().getTag();
|
||||
}
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
||||
Faction faction = fPlayer.getFaction();
|
||||
switch (placeholder) {
|
||||
// First list player stuff
|
||||
case "player_name":
|
||||
return fPlayer.getName();
|
||||
case "player_lastseen":
|
||||
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fPlayer.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
|
||||
return fPlayer.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fPlayer.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
|
||||
case "player_group":
|
||||
return P.p.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fPlayer.getId())));
|
||||
case "player_balance":
|
||||
return Econ.isSetup() ? Econ.getFriendlyBalance(fPlayer) : TL.ECON_OFF.format("balance");
|
||||
case "player_power":
|
||||
return String.valueOf(fPlayer.getPowerRounded());
|
||||
case "player_maxpower":
|
||||
return String.valueOf(fPlayer.getPowerMaxRounded());
|
||||
case "player_kills":
|
||||
return String.valueOf(fPlayer.getKills());
|
||||
case "player_deaths":
|
||||
return String.valueOf(fPlayer.getDeaths());
|
||||
case "player_role_prefix":
|
||||
return String.valueOf(fPlayer.getRolePrefix());
|
||||
case "player_role":
|
||||
return fPlayer.hasFaction() ? fPlayer.getRole().getPrefix() : "";
|
||||
case "player_role_name":
|
||||
return fPlayer.hasFaction() ? fPlayer.getRole().getTranslation().toString() : TL.PLACEHOLDER_ROLE_NAME.toString();
|
||||
// Then Faction stuff
|
||||
case "faction_name":
|
||||
return fPlayer.hasFaction() ? faction.getTag() : TL.NOFACTION_PREFIX.toString();
|
||||
case "faction_power":
|
||||
return String.valueOf(faction.getPowerRounded());
|
||||
case "faction_powermax":
|
||||
return String.valueOf(faction.getPowerMaxRounded());
|
||||
case "faction_description":
|
||||
return faction.getDescription();
|
||||
case "faction_claims":
|
||||
return String.valueOf(faction.getAllClaims().size());
|
||||
case "faction_founded":
|
||||
return TL.sdf.format(faction.getFoundedDate());
|
||||
case "faction_joining":
|
||||
return (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString());
|
||||
case "faction_peaceful":
|
||||
return faction.isPeaceful() ? Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString() : "";
|
||||
case "faction_tntbank_balance":
|
||||
return String.valueOf(faction.getTnt());
|
||||
case "faction_powerboost":
|
||||
double powerBoost = faction.getPowerBoost();
|
||||
return (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString()) + powerBoost + ")";
|
||||
case "faction_leader":
|
||||
FPlayer fAdmin = faction.getFPlayerAdmin();
|
||||
return fAdmin == null ? "Server" : fAdmin.getName().substring(0, fAdmin.getName().length() > 14 ? 13 : fAdmin.getName().length());
|
||||
case "faction_warps":
|
||||
return String.valueOf(faction.getWarps().size());
|
||||
case "faction_raidable":
|
||||
boolean raid = P.p.getConfig().getBoolean("hcf.raidable", false) && faction.getLandRounded() >= faction.getPowerRounded();
|
||||
return raid ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString();
|
||||
case "faction_home_world":
|
||||
return faction.hasHome() ? faction.getHome().getWorld().getName() : "";
|
||||
case "faction_home_x":
|
||||
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockX()) : "";
|
||||
case "faction_home_y":
|
||||
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockY()) : "";
|
||||
case "faction_home_z":
|
||||
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockZ()) : "";
|
||||
case "facion_land_value":
|
||||
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(faction.getLandRounded())) : TL.ECON_OFF.format("value");
|
||||
case "faction_land_refund":
|
||||
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(faction.getLandRounded())) : TL.ECON_OFF.format("refund");
|
||||
case "faction_bank_balance":
|
||||
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.getBalance(faction.getAccountId())) : TL.ECON_OFF.format("balance");
|
||||
case "faction_allies":
|
||||
return String.valueOf(faction.getRelationCount(Relation.ALLY));
|
||||
case "faction_enemies":
|
||||
return String.valueOf(faction.getRelationCount(Relation.ENEMY));
|
||||
case "faction_truces":
|
||||
return String.valueOf(faction.getRelationCount(Relation.TRUCE));
|
||||
case "faction_online":
|
||||
return String.valueOf(faction.getOnlinePlayers().size());
|
||||
case "faction_offline":
|
||||
return String.valueOf(faction.getFPlayers().size() - faction.getOnlinePlayers().size());
|
||||
case "faction_size":
|
||||
return String.valueOf(faction.getFPlayers().size());
|
||||
case "faction_kills":
|
||||
return String.valueOf(faction.getKills());
|
||||
case "faction_deaths":
|
||||
return String.valueOf(faction.getDeaths());
|
||||
case "faction_maxvaults":
|
||||
return String.valueOf(faction.getMaxVaults());
|
||||
case "faction_grace":
|
||||
return String.valueOf(Conf.gracePeriod);
|
||||
case "faction_name_at_location":
|
||||
Faction factionAtLocation = Board.getInstance().getFactionAt(new FLocation(player.getLocation()));
|
||||
return factionAtLocation != null ? factionAtLocation.getTag() : Factions.getInstance().getWilderness().getTag();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -15,52 +15,52 @@ import java.util.Map;
|
||||
|
||||
public final class EnumTypeAdapter<T extends Enum<T>> extends TypeAdapter<T> {
|
||||
|
||||
public static final TypeAdapterFactory ENUM_FACTORY = newEnumTypeHierarchyFactory();
|
||||
private final Map<String, T> nameToConstant = new HashMap<>();
|
||||
private final Map<T, String> constantToName = new HashMap<>();
|
||||
public static final TypeAdapterFactory ENUM_FACTORY = newEnumTypeHierarchyFactory();
|
||||
private final Map<String, T> nameToConstant = new HashMap<>();
|
||||
private final Map<T, String> constantToName = new HashMap<>();
|
||||
|
||||
public EnumTypeAdapter(Class<T> classOfT) {
|
||||
try {
|
||||
for (T constant : classOfT.getEnumConstants()) {
|
||||
String name = constant.name();
|
||||
SerializedName annotation = classOfT.getField(name).getAnnotation(SerializedName.class);
|
||||
if (annotation != null) {
|
||||
name = annotation.value();
|
||||
}
|
||||
nameToConstant.put(name, constant);
|
||||
constantToName.put(constant, name);
|
||||
}
|
||||
} catch (NoSuchFieldException e) {
|
||||
// ignore since it could be a modified enum
|
||||
}
|
||||
}
|
||||
public EnumTypeAdapter(Class<T> classOfT) {
|
||||
try {
|
||||
for (T constant : classOfT.getEnumConstants()) {
|
||||
String name = constant.name();
|
||||
SerializedName annotation = classOfT.getField(name).getAnnotation(SerializedName.class);
|
||||
if (annotation != null) {
|
||||
name = annotation.value();
|
||||
}
|
||||
nameToConstant.put(name, constant);
|
||||
constantToName.put(constant, name);
|
||||
}
|
||||
} catch (NoSuchFieldException e) {
|
||||
// ignore since it could be a modified enum
|
||||
}
|
||||
}
|
||||
|
||||
public static <TT> TypeAdapterFactory newEnumTypeHierarchyFactory() {
|
||||
return new TypeAdapterFactory() {
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
|
||||
Class<? super T> rawType = typeToken.getRawType();
|
||||
if (!Enum.class.isAssignableFrom(rawType) || rawType == Enum.class) {
|
||||
return null;
|
||||
}
|
||||
if (!rawType.isEnum()) {
|
||||
rawType = rawType.getSuperclass(); // handle anonymous subclasses
|
||||
}
|
||||
return (TypeAdapter<T>) new EnumTypeAdapter(rawType);
|
||||
}
|
||||
};
|
||||
}
|
||||
public static <TT> TypeAdapterFactory newEnumTypeHierarchyFactory() {
|
||||
return new TypeAdapterFactory() {
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
|
||||
Class<? super T> rawType = typeToken.getRawType();
|
||||
if (!Enum.class.isAssignableFrom(rawType) || rawType == Enum.class) {
|
||||
return null;
|
||||
}
|
||||
if (!rawType.isEnum()) {
|
||||
rawType = rawType.getSuperclass(); // handle anonymous subclasses
|
||||
}
|
||||
return (TypeAdapter<T>) new EnumTypeAdapter(rawType);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public T read(JsonReader in) throws IOException {
|
||||
if (in.peek() == JsonToken.NULL) {
|
||||
in.nextNull();
|
||||
return null;
|
||||
}
|
||||
return nameToConstant.get(in.nextString());
|
||||
}
|
||||
public T read(JsonReader in) throws IOException {
|
||||
if (in.peek() == JsonToken.NULL) {
|
||||
in.nextNull();
|
||||
return null;
|
||||
}
|
||||
return nameToConstant.get(in.nextString());
|
||||
}
|
||||
|
||||
public void write(JsonWriter out, T value) throws IOException {
|
||||
out.value(value == null ? null : constantToName.get(value));
|
||||
}
|
||||
public void write(JsonWriter out, T value) throws IOException {
|
||||
out.value(value == null ? null : constantToName.get(value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public interface FactionGUI extends InventoryHolder {
|
||||
|
||||
void onClick(int slot, ClickType action);
|
||||
void onClick(int slot, ClickType action);
|
||||
|
||||
void build();
|
||||
void build();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,21 +4,20 @@ import com.github.stefvanschie.inventoryframework.Gui;
|
||||
import com.github.stefvanschie.inventoryframework.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import java.util.Map;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class FactionWarpsFrame {
|
||||
|
||||
@@ -27,7 +26,7 @@ public class FactionWarpsFrame {
|
||||
|
||||
public FactionWarpsFrame(final Faction f) {
|
||||
this.section = P.p.getConfig().getConfigurationSection("fwarp-gui");
|
||||
this.gui = new Gui(P.p, section.getInt("rows", 3), P.p.color(this.section.getString("name").replace("{faction}",f.getTag())));
|
||||
this.gui = new Gui(P.p, section.getInt("rows", 3), P.p.color(this.section.getString("name").replace("{faction}", f.getTag())));
|
||||
}
|
||||
|
||||
public void buildGUI(final FPlayer fplayer) {
|
||||
@@ -35,7 +34,8 @@ public class FactionWarpsFrame {
|
||||
final List<GuiItem> GUIItems = new ArrayList<>();
|
||||
final List<Integer> slots = section.getIntegerList("warp-slots");
|
||||
int count = 0;
|
||||
for (int x = 0; x <= gui.getRows() * 9 - 1; ++x) GUIItems.add(new GuiItem(buildDummyItem(), e -> e.setCancelled(true)));
|
||||
for (int x = 0; x <= gui.getRows() * 9 - 1; ++x)
|
||||
GUIItems.add(new GuiItem(buildDummyItem(), e -> e.setCancelled(true)));
|
||||
slots.forEach(slot -> GUIItems.set(slot, new GuiItem(XMaterial.AIR.parseItem())));
|
||||
for (final Map.Entry<String, LazyLocation> warp : fplayer.getFaction().getWarps().entrySet()) {
|
||||
if (count > slots.size()) continue;
|
||||
|
||||
@@ -8,20 +8,20 @@ import java.lang.reflect.Type;
|
||||
public class InventoryTypeAdapter implements JsonSerializer<Inventory>, JsonDeserializer<Inventory> {
|
||||
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Inventory inventory, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
@Override
|
||||
public JsonElement serialize(Inventory inventory, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
|
||||
JsonObject object = new JsonObject();
|
||||
object.add("contents", new JsonPrimitive(InventoryUtil.toBase64(inventory)));
|
||||
return object;
|
||||
}
|
||||
JsonObject object = new JsonObject();
|
||||
object.add("contents", new JsonPrimitive(InventoryUtil.toBase64(inventory)));
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Inventory deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
|
||||
JsonObject object = jsonElement.getAsJsonObject();
|
||||
return InventoryUtil.fromBase64(object.get("contents").getAsString());
|
||||
}
|
||||
@Override
|
||||
public Inventory deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
|
||||
JsonObject object = jsonElement.getAsJsonObject();
|
||||
return InventoryUtil.fromBase64(object.get("contents").getAsString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,78 +14,78 @@ import java.io.IOException;
|
||||
public class InventoryUtil {
|
||||
|
||||
|
||||
public static String InventoryToString(ItemStack[] items) throws IllegalStateException {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
dataOutput.writeInt(items.length);
|
||||
for (ItemStack item : items) {
|
||||
dataOutput.writeObject(item);
|
||||
}
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to save item stacks.", e);
|
||||
}
|
||||
}
|
||||
public static String InventoryToString(ItemStack[] items) throws IllegalStateException {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
dataOutput.writeInt(items.length);
|
||||
for (ItemStack item : items) {
|
||||
dataOutput.writeObject(item);
|
||||
}
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to save item stacks.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack[] StringToInventory(String data) throws IOException {
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
ItemStack[] items = new ItemStack[dataInput.readInt()];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = (ItemStack) dataInput.readObject();
|
||||
}
|
||||
dataInput.close();
|
||||
return items;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IOException("Unable to decode class type.", e);
|
||||
}
|
||||
}
|
||||
public static ItemStack[] StringToInventory(String data) throws IOException {
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
ItemStack[] items = new ItemStack[dataInput.readInt()];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = (ItemStack) dataInput.readObject();
|
||||
}
|
||||
dataInput.close();
|
||||
return items;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IOException("Unable to decode class type.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toBase64(Inventory inventory) {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
public static String toBase64(Inventory inventory) {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
|
||||
// Write the size of the inventory
|
||||
dataOutput.writeInt(inventory.getSize());
|
||||
// Write the size of the inventory
|
||||
dataOutput.writeInt(inventory.getSize());
|
||||
|
||||
// Save every element in the list
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
dataOutput.writeObject(inventory.getItem(i));
|
||||
}
|
||||
// Save every element in the list
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
dataOutput.writeObject(inventory.getItem(i));
|
||||
}
|
||||
|
||||
// Serialize that array
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot into itemstacksz!", e);
|
||||
}
|
||||
}
|
||||
// Serialize that array
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot into itemstacksz!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toBase64(ItemStack[] is, int size) {
|
||||
Inventory inventory = Bukkit.createInventory(null, size);
|
||||
inventory.setContents(is);
|
||||
return toBase64(inventory);
|
||||
}
|
||||
public static String toBase64(ItemStack[] is, int size) {
|
||||
Inventory inventory = Bukkit.createInventory(null, size);
|
||||
inventory.setContents(is);
|
||||
return toBase64(inventory);
|
||||
}
|
||||
|
||||
public static Inventory fromBase64(String data) {
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt());
|
||||
public static Inventory fromBase64(String data) {
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt());
|
||||
|
||||
// Read the serialized inventory
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, (ItemStack) dataInput.readObject());
|
||||
}
|
||||
dataInput.close();
|
||||
return inventory;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// Read the serialized inventory
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, (ItemStack) dataInput.readObject());
|
||||
}
|
||||
dataInput.close();
|
||||
return inventory;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,90 +12,90 @@ import java.io.Serializable;
|
||||
*/
|
||||
|
||||
public class LazyLocation implements Serializable {
|
||||
private static final long serialVersionUID = -6049901271320963314L;
|
||||
private transient Location location = null;
|
||||
private String worldName;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private float pitch;
|
||||
private float yaw;
|
||||
private static final long serialVersionUID = -6049901271320963314L;
|
||||
private transient Location location = null;
|
||||
private String worldName;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private float pitch;
|
||||
private float yaw;
|
||||
|
||||
public LazyLocation(Location loc) {
|
||||
setLocation(loc);
|
||||
}
|
||||
public LazyLocation(Location loc) {
|
||||
setLocation(loc);
|
||||
}
|
||||
|
||||
public LazyLocation(final String worldName, final double x, final double y, final double z) {
|
||||
this(worldName, x, y, z, 0, 0);
|
||||
}
|
||||
public LazyLocation(final String worldName, final double x, final double y, final double z) {
|
||||
this(worldName, x, y, z, 0, 0);
|
||||
}
|
||||
|
||||
public LazyLocation(final String worldName, final double x, final double y, final double z, final float yaw, final float pitch) {
|
||||
this.worldName = worldName;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
public LazyLocation(final String worldName, final double x, final double y, final double z, final float yaw, final float pitch) {
|
||||
this.worldName = worldName;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
// This returns the actual Location
|
||||
public final Location getLocation() {
|
||||
// make sure Location is initialized before returning it
|
||||
initLocation();
|
||||
return location;
|
||||
}
|
||||
// This returns the actual Location
|
||||
public final Location getLocation() {
|
||||
// make sure Location is initialized before returning it
|
||||
initLocation();
|
||||
return location;
|
||||
}
|
||||
|
||||
// change the Location
|
||||
public final void setLocation(Location loc) {
|
||||
this.location = loc;
|
||||
this.worldName = loc.getWorld().getName();
|
||||
this.x = loc.getX();
|
||||
this.y = loc.getY();
|
||||
this.z = loc.getZ();
|
||||
this.yaw = loc.getYaw();
|
||||
this.pitch = loc.getPitch();
|
||||
}
|
||||
// change the Location
|
||||
public final void setLocation(Location loc) {
|
||||
this.location = loc;
|
||||
this.worldName = loc.getWorld().getName();
|
||||
this.x = loc.getX();
|
||||
this.y = loc.getY();
|
||||
this.z = loc.getZ();
|
||||
this.yaw = loc.getYaw();
|
||||
this.pitch = loc.getPitch();
|
||||
}
|
||||
|
||||
|
||||
// This initializes the Location
|
||||
private void initLocation() {
|
||||
// if location is already initialized, simply return
|
||||
if (location != null) {
|
||||
return;
|
||||
}
|
||||
// This initializes the Location
|
||||
private void initLocation() {
|
||||
// if location is already initialized, simply return
|
||||
if (location != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get World; hopefully it's initialized at this point
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
// get World; hopefully it's initialized at this point
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// store the Location for future calls, and pass it on
|
||||
location = new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
// store the Location for future calls, and pass it on
|
||||
location = new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
|
||||
public final String getWorldName() {
|
||||
return worldName;
|
||||
}
|
||||
public final String getWorldName() {
|
||||
return worldName;
|
||||
}
|
||||
|
||||
public final double getX() {
|
||||
return x;
|
||||
}
|
||||
public final double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public final double getY() {
|
||||
return y;
|
||||
}
|
||||
public final double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public final double getZ() {
|
||||
return z;
|
||||
}
|
||||
public final double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public final double getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
public final double getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public final double getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
public final double getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,41 +10,41 @@ import java.util.logging.Level;
|
||||
|
||||
public class LocationTypeAdapter implements JsonSerializer<Location>, JsonDeserializer<Location> {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Location location, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
JsonObject object = new JsonObject();
|
||||
try {
|
||||
object.add("x", new JsonPrimitive(location.getX()));
|
||||
object.add("y", new JsonPrimitive(location.getY()));
|
||||
object.add("z", new JsonPrimitive(location.getZ()));
|
||||
object.add("world", new JsonPrimitive(location.getWorld().getName()));
|
||||
return object;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a Location.");
|
||||
return object;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public JsonElement serialize(Location location, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
JsonObject object = new JsonObject();
|
||||
try {
|
||||
object.add("x", new JsonPrimitive(location.getX()));
|
||||
object.add("y", new JsonPrimitive(location.getY()));
|
||||
object.add("z", new JsonPrimitive(location.getZ()));
|
||||
object.add("world", new JsonPrimitive(location.getWorld().getName()));
|
||||
return object;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a Location.");
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Location deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
|
||||
JsonObject object = jsonElement.getAsJsonObject();
|
||||
try {
|
||||
@Override
|
||||
public Location deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
|
||||
JsonObject object = jsonElement.getAsJsonObject();
|
||||
try {
|
||||
|
||||
return new Location(Bukkit.getWorld(object.get("world").getAsString()),
|
||||
object.get("x").getAsDouble(),
|
||||
object.get("y").getAsDouble(),
|
||||
object.get("z").getAsDouble());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while" +
|
||||
" deserializing a Location.");
|
||||
return null;
|
||||
}
|
||||
return new Location(Bukkit.getWorld(object.get("world").getAsString()),
|
||||
object.get("x").getAsDouble(),
|
||||
object.get("y").getAsDouble(),
|
||||
object.get("z").getAsDouble());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while" +
|
||||
" deserializing a Location.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,87 +16,87 @@ import java.util.logging.Level;
|
||||
|
||||
public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLocation, Set<String>>>, JsonSerializer<Map<FLocation, Set<String>>> {
|
||||
|
||||
@Override
|
||||
public Map<FLocation, Set<String>> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<FLocation, Set<String>> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<FLocation, Set<String>> locationMap = new ConcurrentHashMap<>();
|
||||
Set<String> nameSet;
|
||||
Iterator<JsonElement> iter;
|
||||
String worldName;
|
||||
String[] coords;
|
||||
int x, z;
|
||||
Map<FLocation, Set<String>> locationMap = new ConcurrentHashMap<>();
|
||||
Set<String> nameSet;
|
||||
Iterator<JsonElement> iter;
|
||||
String worldName;
|
||||
String[] coords;
|
||||
int x, z;
|
||||
|
||||
for (Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
worldName = entry.getKey();
|
||||
for (Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
coords = entry2.getKey().trim().split("[,\\s]+");
|
||||
x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]);
|
||||
for (Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
worldName = entry.getKey();
|
||||
for (Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
coords = entry2.getKey().trim().split("[,\\s]+");
|
||||
x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]);
|
||||
|
||||
nameSet = new HashSet<>();
|
||||
iter = entry2.getValue().getAsJsonArray().iterator();
|
||||
while (iter.hasNext()) nameSet.add(iter.next().getAsString());
|
||||
nameSet = new HashSet<>();
|
||||
iter = entry2.getValue().getAsJsonArray().iterator();
|
||||
while (iter.hasNext()) nameSet.add(iter.next().getAsString());
|
||||
|
||||
locationMap.put(new FLocation(worldName, x, z), nameSet);
|
||||
}
|
||||
}
|
||||
locationMap.put(new FLocation(worldName, x, z), nameSet);
|
||||
}
|
||||
}
|
||||
|
||||
return locationMap;
|
||||
return locationMap;
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a Map of FLocations to String Sets.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a Map of FLocations to String Sets.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Map<FLocation, Set<String>> src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject obj = new JsonObject();
|
||||
@Override
|
||||
public JsonElement serialize(Map<FLocation, Set<String>> src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
try {
|
||||
if (src != null) {
|
||||
FLocation loc;
|
||||
String locWorld;
|
||||
Set<String> nameSet;
|
||||
Iterator<String> iter;
|
||||
JsonArray nameArray;
|
||||
JsonPrimitive nameElement;
|
||||
try {
|
||||
if (src != null) {
|
||||
FLocation loc;
|
||||
String locWorld;
|
||||
Set<String> nameSet;
|
||||
Iterator<String> iter;
|
||||
JsonArray nameArray;
|
||||
JsonPrimitive nameElement;
|
||||
|
||||
for (Entry<FLocation, Set<String>> entry : src.entrySet()) {
|
||||
loc = entry.getKey();
|
||||
locWorld = loc.getWorldName();
|
||||
nameSet = entry.getValue();
|
||||
for (Entry<FLocation, Set<String>> entry : src.entrySet()) {
|
||||
loc = entry.getKey();
|
||||
locWorld = loc.getWorldName();
|
||||
nameSet = entry.getValue();
|
||||
|
||||
if (nameSet == null || nameSet.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (nameSet == null || nameSet.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nameArray = new JsonArray();
|
||||
iter = nameSet.iterator();
|
||||
while (iter.hasNext()) {
|
||||
nameElement = new JsonPrimitive(iter.next());
|
||||
nameArray.add(nameElement);
|
||||
}
|
||||
nameArray = new JsonArray();
|
||||
iter = nameSet.iterator();
|
||||
while (iter.hasNext()) {
|
||||
nameElement = new JsonPrimitive(iter.next());
|
||||
nameArray.add(nameElement);
|
||||
}
|
||||
|
||||
if (!obj.has(locWorld)) {
|
||||
obj.add(locWorld, new JsonObject());
|
||||
}
|
||||
if (!obj.has(locWorld)) {
|
||||
obj.add(locWorld, new JsonObject());
|
||||
}
|
||||
|
||||
obj.get(locWorld).getAsJsonObject().add(loc.getCoordString(), nameArray);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
obj.get(locWorld).getAsJsonObject().add(loc.getCoordString(), nameArray);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a Map of FLocations to String Sets.");
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a Map of FLocations to String Sets.");
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,113 +18,113 @@ import java.util.logging.Level;
|
||||
|
||||
public class MiscUtil {
|
||||
|
||||
/// TODO create tag whitelist!!
|
||||
public static HashSet<String> substanceChars =
|
||||
new HashSet<>(Arrays.asList("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("")));
|
||||
/// TODO create tag whitelist!!
|
||||
public static HashSet<String> substanceChars =
|
||||
new HashSet<>(Arrays.asList("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("")));
|
||||
|
||||
public static EntityType creatureTypeFromEntity(Entity entity) {
|
||||
if (!(entity instanceof Creature)) {
|
||||
return null;
|
||||
}
|
||||
public static EntityType creatureTypeFromEntity(Entity entity) {
|
||||
if (!(entity instanceof Creature)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = entity.getClass().getSimpleName();
|
||||
name = name.substring(5); // Remove "Craft"
|
||||
String name = entity.getClass().getSimpleName();
|
||||
name = name.substring(5); // Remove "Craft"
|
||||
|
||||
return EntityType.fromName(name);
|
||||
}
|
||||
return EntityType.fromName(name);
|
||||
}
|
||||
|
||||
// Inclusive range
|
||||
public static long[] range(long start, long end) {
|
||||
long[] values = new long[(int) Math.abs(end - start) + 1];
|
||||
// Inclusive range
|
||||
public static long[] range(long start, long end) {
|
||||
long[] values = new long[(int) Math.abs(end - start) + 1];
|
||||
|
||||
if (end < start) {
|
||||
long oldstart = start;
|
||||
start = end;
|
||||
end = oldstart;
|
||||
}
|
||||
if (end < start) {
|
||||
long oldstart = start;
|
||||
start = end;
|
||||
end = oldstart;
|
||||
}
|
||||
|
||||
for (long i = start; i <= end; i++) {
|
||||
values[(int) (i - start)] = i;
|
||||
}
|
||||
for (long i = start; i <= end; i++) {
|
||||
values[(int) (i - start)] = i;
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static String getComparisonString(String str) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
public static String getComparisonString(String str) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
|
||||
str = ChatColor.stripColor(str);
|
||||
str = str.toLowerCase();
|
||||
str = ChatColor.stripColor(str);
|
||||
str = str.toLowerCase();
|
||||
|
||||
for (char c : str.toCharArray()) {
|
||||
if (substanceChars.contains(String.valueOf(c))) {
|
||||
ret.append(c);
|
||||
}
|
||||
}
|
||||
return ret.toString().toLowerCase();
|
||||
}
|
||||
for (char c : str.toCharArray()) {
|
||||
if (substanceChars.contains(String.valueOf(c))) {
|
||||
ret.append(c);
|
||||
}
|
||||
}
|
||||
return ret.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static ArrayList<String> validateTag(String str) {
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
public static ArrayList<String> validateTag(String str) {
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
if (getComparisonString(str).length() < Conf.factionTagLengthMin) {
|
||||
errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_TOOSHORT.toString(), Conf.factionTagLengthMin));
|
||||
}
|
||||
if (getComparisonString(str).length() < Conf.factionTagLengthMin) {
|
||||
errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_TOOSHORT.toString(), Conf.factionTagLengthMin));
|
||||
}
|
||||
|
||||
if (str.length() > Conf.factionTagLengthMax) {
|
||||
errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_TOOLONG.toString(), Conf.factionTagLengthMax));
|
||||
}
|
||||
if (str.length() > Conf.factionTagLengthMax) {
|
||||
errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_TOOLONG.toString(), Conf.factionTagLengthMax));
|
||||
}
|
||||
|
||||
for (char c : str.toCharArray()) {
|
||||
if (!substanceChars.contains(String.valueOf(c))) {
|
||||
errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_ALPHANUMERIC.toString(), c));
|
||||
}
|
||||
}
|
||||
for (char c : str.toCharArray()) {
|
||||
if (!substanceChars.contains(String.valueOf(c))) {
|
||||
errors.add(P.p.txt.parse(TL.GENERIC_FACTIONTAG_ALPHANUMERIC.toString(), c));
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
public static Iterable<FPlayer> rankOrder(Iterable<FPlayer> players) {
|
||||
List<FPlayer> admins = new ArrayList<>();
|
||||
List<FPlayer> coleaders = new ArrayList<>();
|
||||
List<FPlayer> moderators = new ArrayList<>();
|
||||
List<FPlayer> normal = new ArrayList<>();
|
||||
List<FPlayer> recruit = new ArrayList<>();
|
||||
public static Iterable<FPlayer> rankOrder(Iterable<FPlayer> players) {
|
||||
List<FPlayer> admins = new ArrayList<>();
|
||||
List<FPlayer> coleaders = new ArrayList<>();
|
||||
List<FPlayer> moderators = new ArrayList<>();
|
||||
List<FPlayer> normal = new ArrayList<>();
|
||||
List<FPlayer> recruit = new ArrayList<>();
|
||||
|
||||
for (FPlayer player : players) {
|
||||
for (FPlayer player : players) {
|
||||
|
||||
// Fix for some data being broken when we added the recruit rank.
|
||||
if (player.getRole() == null) {
|
||||
player.setRole(Role.NORMAL);
|
||||
P.p.log(Level.WARNING, String.format("Player %s had null role. Setting them to normal. This isn't good D:", player.getName()));
|
||||
}
|
||||
// Fix for some data being broken when we added the recruit rank.
|
||||
if (player.getRole() == null) {
|
||||
player.setRole(Role.NORMAL);
|
||||
P.p.log(Level.WARNING, String.format("Player %s had null role. Setting them to normal. This isn't good D:", player.getName()));
|
||||
}
|
||||
|
||||
switch (player.getRole()) {
|
||||
case LEADER:
|
||||
admins.add(player);
|
||||
break;
|
||||
case COLEADER:
|
||||
admins.add(player);
|
||||
break;
|
||||
case MODERATOR:
|
||||
moderators.add(player);
|
||||
break;
|
||||
case NORMAL:
|
||||
normal.add(player);
|
||||
break;
|
||||
case RECRUIT:
|
||||
recruit.add(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (player.getRole()) {
|
||||
case LEADER:
|
||||
admins.add(player);
|
||||
break;
|
||||
case COLEADER:
|
||||
admins.add(player);
|
||||
break;
|
||||
case MODERATOR:
|
||||
moderators.add(player);
|
||||
break;
|
||||
case NORMAL:
|
||||
normal.add(player);
|
||||
break;
|
||||
case RECRUIT:
|
||||
recruit.add(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
List<FPlayer> ret = new ArrayList<>();
|
||||
ret.addAll(admins);
|
||||
ret.addAll(coleaders);
|
||||
ret.addAll(moderators);
|
||||
ret.addAll(normal);
|
||||
ret.addAll(recruit);
|
||||
return ret;
|
||||
}
|
||||
List<FPlayer> ret = new ArrayList<>();
|
||||
ret.addAll(admins);
|
||||
ret.addAll(coleaders);
|
||||
ret.addAll(moderators);
|
||||
ret.addAll(normal);
|
||||
ret.addAll(recruit);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,51 +9,51 @@ import java.util.logging.Level;
|
||||
|
||||
public class MyLocationTypeAdapter implements JsonDeserializer<LazyLocation>, JsonSerializer<LazyLocation> {
|
||||
|
||||
private static final String WORLD = "world";
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
private static final String Z = "z";
|
||||
private static final String YAW = "yaw";
|
||||
private static final String PITCH = "pitch";
|
||||
private static final String WORLD = "world";
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
private static final String Z = "z";
|
||||
private static final String YAW = "yaw";
|
||||
private static final String PITCH = "pitch";
|
||||
|
||||
@Override
|
||||
public LazyLocation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
@Override
|
||||
public LazyLocation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
|
||||
String worldName = obj.get(WORLD).getAsString();
|
||||
double x = obj.get(X).getAsDouble();
|
||||
double y = obj.get(Y).getAsDouble();
|
||||
double z = obj.get(Z).getAsDouble();
|
||||
float yaw = obj.get(YAW).getAsFloat();
|
||||
float pitch = obj.get(PITCH).getAsFloat();
|
||||
String worldName = obj.get(WORLD).getAsString();
|
||||
double x = obj.get(X).getAsDouble();
|
||||
double y = obj.get(Y).getAsDouble();
|
||||
double z = obj.get(Z).getAsDouble();
|
||||
float yaw = obj.get(YAW).getAsFloat();
|
||||
float pitch = obj.get(PITCH).getAsFloat();
|
||||
|
||||
return new LazyLocation(worldName, x, y, z, yaw, pitch);
|
||||
return new LazyLocation(worldName, x, y, z, yaw, pitch);
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a LazyLocation.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a LazyLocation.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(LazyLocation src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject obj = new JsonObject();
|
||||
@Override
|
||||
public JsonElement serialize(LazyLocation src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
try {
|
||||
obj.addProperty(WORLD, src.getWorldName());
|
||||
obj.addProperty(X, src.getX());
|
||||
obj.addProperty(Y, src.getY());
|
||||
obj.addProperty(Z, src.getZ());
|
||||
obj.addProperty(YAW, src.getYaw());
|
||||
obj.addProperty(PITCH, src.getPitch());
|
||||
try {
|
||||
obj.addProperty(WORLD, src.getWorldName());
|
||||
obj.addProperty(X, src.getX());
|
||||
obj.addProperty(Y, src.getY());
|
||||
obj.addProperty(Z, src.getZ());
|
||||
obj.addProperty(YAW, src.getYaw());
|
||||
obj.addProperty(PITCH, src.getPitch());
|
||||
|
||||
return obj;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a LazyLocation.");
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a LazyLocation.");
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -17,82 +17,82 @@ import java.util.logging.Level;
|
||||
|
||||
public class PermissionsMapTypeAdapter implements JsonDeserializer<Map<Permissable, Map<PermissableAction, Access>>> {
|
||||
|
||||
@Override
|
||||
public Map<Permissable, Map<PermissableAction, Access>> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
@Override
|
||||
public Map<Permissable, Map<PermissableAction, Access>> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<Permissable, Map<PermissableAction, Access>> permissionsMap = new ConcurrentHashMap<>();
|
||||
Map<Permissable, Map<PermissableAction, Access>> permissionsMap = new ConcurrentHashMap<>();
|
||||
|
||||
// Top level is Relation
|
||||
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
Permissable permissable = getPermissable(entry.getKey());
|
||||
// Top level is Relation
|
||||
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
Permissable permissable = getPermissable(entry.getKey());
|
||||
|
||||
if (permissable == null) {
|
||||
continue;
|
||||
}
|
||||
if (permissable == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Second level is the map between action -> access
|
||||
Map<PermissableAction, Access> accessMap = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
PermissableAction permissableAction = PermissableAction.fromString(entry2.getKey());
|
||||
if (permissableAction == null) {
|
||||
switch (entry2.getKey()) {
|
||||
case "frostwalk":
|
||||
permissableAction = PermissableAction.FROST_WALK;
|
||||
break;
|
||||
case "painbuild":
|
||||
permissableAction = PermissableAction.PAIN_BUILD;
|
||||
break;
|
||||
case "items":
|
||||
permissableAction = PermissableAction.ITEM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Access access = Access.fromString(entry2.getValue().getAsString());
|
||||
accessMap.put(permissableAction, access);
|
||||
}
|
||||
permissionsMap.put(permissable, accessMap);
|
||||
}
|
||||
// Second level is the map between action -> access
|
||||
Map<PermissableAction, Access> accessMap = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
PermissableAction permissableAction = PermissableAction.fromString(entry2.getKey());
|
||||
if (permissableAction == null) {
|
||||
switch (entry2.getKey()) {
|
||||
case "frostwalk":
|
||||
permissableAction = PermissableAction.FROST_WALK;
|
||||
break;
|
||||
case "painbuild":
|
||||
permissableAction = PermissableAction.PAIN_BUILD;
|
||||
break;
|
||||
case "items":
|
||||
permissableAction = PermissableAction.ITEM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Access access = Access.fromString(entry2.getValue().getAsString());
|
||||
accessMap.put(permissableAction, access);
|
||||
}
|
||||
permissionsMap.put(permissable, accessMap);
|
||||
}
|
||||
|
||||
return permissionsMap;
|
||||
return permissionsMap;
|
||||
|
||||
} catch (Exception ex) {
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a PermissionsMap.");
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a PermissionsMap.");
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Permissable getPermissable(String name) {
|
||||
// If name is uppercase then it is (probably, no way to completely know) valid if not begin conversion
|
||||
if (name.equals(name.toUpperCase())) {
|
||||
if (Role.fromString(name.toUpperCase()) != null) {
|
||||
return Role.fromString(name.toUpperCase());
|
||||
} else if (Relation.fromString(name.toUpperCase()) != null) {
|
||||
return Relation.fromString(name.toUpperCase());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (name.equals(TL.ROLE_RECRUIT.toString())) {
|
||||
return Role.RECRUIT;
|
||||
} else if (name.equals(TL.ROLE_NORMAL.toString())) {
|
||||
return Role.NORMAL;
|
||||
} else if (name.equals(TL.ROLE_MODERATOR.toString())) {
|
||||
return Role.MODERATOR;
|
||||
} else {
|
||||
// If it is explicitly member and its old data then it refers to relation member not role, skip it
|
||||
if (name.equals("member")) {
|
||||
return null;
|
||||
}
|
||||
return Relation.fromString(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Permissable getPermissable(String name) {
|
||||
// If name is uppercase then it is (probably, no way to completely know) valid if not begin conversion
|
||||
if (name.equals(name.toUpperCase())) {
|
||||
if (Role.fromString(name.toUpperCase()) != null) {
|
||||
return Role.fromString(name.toUpperCase());
|
||||
} else if (Relation.fromString(name.toUpperCase()) != null) {
|
||||
return Relation.fromString(name.toUpperCase());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (name.equals(TL.ROLE_RECRUIT.toString())) {
|
||||
return Role.RECRUIT;
|
||||
} else if (name.equals(TL.ROLE_NORMAL.toString())) {
|
||||
return Role.NORMAL;
|
||||
} else if (name.equals(TL.ROLE_MODERATOR.toString())) {
|
||||
return Role.MODERATOR;
|
||||
} else {
|
||||
// If it is explicitly member and its old data then it refers to relation member not role, skip it
|
||||
if (name.equals("member")) {
|
||||
return null;
|
||||
}
|
||||
return Relation.fromString(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,101 +11,101 @@ import org.bukkit.ChatColor;
|
||||
|
||||
public class RelationUtil {
|
||||
|
||||
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) {
|
||||
String ret = "";
|
||||
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) {
|
||||
String ret = "";
|
||||
|
||||
Faction thatFaction = getFaction(that);
|
||||
if (thatFaction == null) {
|
||||
return "ERROR"; // ERROR
|
||||
}
|
||||
Faction thatFaction = getFaction(that);
|
||||
if (thatFaction == null) {
|
||||
return "ERROR"; // ERROR
|
||||
}
|
||||
|
||||
Faction myFaction = getFaction(me);
|
||||
Faction myFaction = getFaction(me);
|
||||
// if (myFaction == null) return that.describeTo(null); // no relation, but can show basic name or tag
|
||||
|
||||
if (that instanceof Faction) {
|
||||
if (me instanceof FPlayer && myFaction == thatFaction) {
|
||||
ret = TL.GENERIC_YOURFACTION.toString();
|
||||
} else {
|
||||
ret = thatFaction.getTag();
|
||||
}
|
||||
} else if (that instanceof FPlayer) {
|
||||
FPlayer fplayerthat = (FPlayer) that;
|
||||
if (that == me) {
|
||||
ret = TL.GENERIC_YOU.toString();
|
||||
} else if (thatFaction == myFaction) {
|
||||
ret = fplayerthat.getNameAndTitle();
|
||||
} else {
|
||||
ret = fplayerthat.getNameAndTag();
|
||||
}
|
||||
}
|
||||
if (that instanceof Faction) {
|
||||
if (me instanceof FPlayer && myFaction == thatFaction) {
|
||||
ret = TL.GENERIC_YOURFACTION.toString();
|
||||
} else {
|
||||
ret = thatFaction.getTag();
|
||||
}
|
||||
} else if (that instanceof FPlayer) {
|
||||
FPlayer fplayerthat = (FPlayer) that;
|
||||
if (that == me) {
|
||||
ret = TL.GENERIC_YOU.toString();
|
||||
} else if (thatFaction == myFaction) {
|
||||
ret = fplayerthat.getNameAndTitle();
|
||||
} else {
|
||||
ret = fplayerthat.getNameAndTag();
|
||||
}
|
||||
}
|
||||
|
||||
if (ucfirst) {
|
||||
ret = TextUtil.upperCaseFirst(ret);
|
||||
}
|
||||
if (ucfirst) {
|
||||
ret = TextUtil.upperCaseFirst(ret);
|
||||
}
|
||||
|
||||
return "" + getColorOfThatToMe(that, me) + ret;
|
||||
}
|
||||
return "" + getColorOfThatToMe(that, me) + ret;
|
||||
}
|
||||
|
||||
public static String describeThatToMe(RelationParticipator that, RelationParticipator me) {
|
||||
return describeThatToMe(that, me, false);
|
||||
}
|
||||
public static String describeThatToMe(RelationParticipator that, RelationParticipator me) {
|
||||
return describeThatToMe(that, me, false);
|
||||
}
|
||||
|
||||
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that) {
|
||||
return getRelationTo(that, me, false);
|
||||
}
|
||||
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that) {
|
||||
return getRelationTo(that, me, false);
|
||||
}
|
||||
|
||||
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) {
|
||||
Faction fthat = getFaction(that);
|
||||
Faction fme = getFaction(me);
|
||||
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) {
|
||||
Faction fthat = getFaction(that);
|
||||
Faction fme = getFaction(me);
|
||||
|
||||
if (fthat == null || fme == null) {
|
||||
return Relation.NEUTRAL; // ERROR
|
||||
}
|
||||
if (fthat == null || fme == null) {
|
||||
return Relation.NEUTRAL; // ERROR
|
||||
}
|
||||
|
||||
if (!fthat.isNormal() || !fme.isNormal()) {
|
||||
return Relation.NEUTRAL;
|
||||
}
|
||||
if (!fthat.isNormal() || !fme.isNormal()) {
|
||||
return Relation.NEUTRAL;
|
||||
}
|
||||
|
||||
if (fthat.equals(fme)) {
|
||||
return Relation.MEMBER;
|
||||
}
|
||||
if (fthat.equals(fme)) {
|
||||
return Relation.MEMBER;
|
||||
}
|
||||
|
||||
if (!ignorePeaceful && (fme.isPeaceful() || fthat.isPeaceful())) {
|
||||
return Relation.NEUTRAL;
|
||||
}
|
||||
if (!ignorePeaceful && (fme.isPeaceful() || fthat.isPeaceful())) {
|
||||
return Relation.NEUTRAL;
|
||||
}
|
||||
|
||||
if (fme.getRelationWish(fthat).value >= fthat.getRelationWish(fme).value) {
|
||||
return fthat.getRelationWish(fme);
|
||||
}
|
||||
if (fme.getRelationWish(fthat).value >= fthat.getRelationWish(fme).value) {
|
||||
return fthat.getRelationWish(fme);
|
||||
}
|
||||
|
||||
return fme.getRelationWish(fthat);
|
||||
}
|
||||
return fme.getRelationWish(fthat);
|
||||
}
|
||||
|
||||
public static Faction getFaction(RelationParticipator rp) {
|
||||
if (rp instanceof Faction) {
|
||||
return (Faction) rp;
|
||||
}
|
||||
public static Faction getFaction(RelationParticipator rp) {
|
||||
if (rp instanceof Faction) {
|
||||
return (Faction) rp;
|
||||
}
|
||||
|
||||
if (rp instanceof FPlayer) {
|
||||
return ((FPlayer) rp).getFaction();
|
||||
}
|
||||
if (rp instanceof FPlayer) {
|
||||
return ((FPlayer) rp).getFaction();
|
||||
}
|
||||
|
||||
// ERROR
|
||||
return null;
|
||||
}
|
||||
// ERROR
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) {
|
||||
Faction thatFaction = getFaction(that);
|
||||
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) {
|
||||
Faction thatFaction = getFaction(that);
|
||||
|
||||
if (thatFaction != null && thatFaction != getFaction(me)) {
|
||||
if (thatFaction.isPeaceful())
|
||||
return Conf.colorPeaceful;
|
||||
else if (thatFaction.isSafeZone())
|
||||
return Conf.colorPeaceful;
|
||||
else if (thatFaction.isWarZone())
|
||||
return Conf.colorWar;
|
||||
}
|
||||
if (thatFaction != null && thatFaction != getFaction(me)) {
|
||||
if (thatFaction.isPeaceful())
|
||||
return Conf.colorPeaceful;
|
||||
else if (thatFaction.isSafeZone())
|
||||
return Conf.colorPeaceful;
|
||||
else if (thatFaction.isWarZone())
|
||||
return Conf.colorWar;
|
||||
}
|
||||
|
||||
return getRelationTo(that, me).getColor();
|
||||
}
|
||||
return getRelationTo(that, me).getColor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,186 +24,186 @@ import java.util.logging.Level;
|
||||
|
||||
public abstract class SpiralTask implements Runnable {
|
||||
|
||||
// general task-related reference data
|
||||
private transient World world = null;
|
||||
private transient boolean readyToGo = false;
|
||||
private transient int taskID = -1;
|
||||
private transient int limit = 0;
|
||||
// general task-related reference data
|
||||
private transient World world = null;
|
||||
private transient boolean readyToGo = false;
|
||||
private transient int taskID = -1;
|
||||
private transient int limit = 0;
|
||||
|
||||
// values for the spiral pattern routine
|
||||
private transient int x = 0;
|
||||
private transient int z = 0;
|
||||
private transient boolean isZLeg = false;
|
||||
private transient boolean isNeg = false;
|
||||
private transient int length = -1;
|
||||
private transient int current = 0;
|
||||
// values for the spiral pattern routine
|
||||
private transient int x = 0;
|
||||
private transient int z = 0;
|
||||
private transient boolean isZLeg = false;
|
||||
private transient boolean isNeg = false;
|
||||
private transient int length = -1;
|
||||
private transient int current = 0;
|
||||
|
||||
@SuppressWarnings("LeakingThisInConstructor")
|
||||
public SpiralTask(FLocation fLocation, int radius) {
|
||||
// limit is determined based on spiral leg length for given radius; see insideRadius()
|
||||
this.limit = (radius - 1) * 2;
|
||||
@SuppressWarnings("LeakingThisInConstructor")
|
||||
public SpiralTask(FLocation fLocation, int radius) {
|
||||
// limit is determined based on spiral leg length for given radius; see insideRadius()
|
||||
this.limit = (radius - 1) * 2;
|
||||
|
||||
this.world = Bukkit.getWorld(fLocation.getWorldName());
|
||||
if (this.world == null) {
|
||||
P.p.log(Level.WARNING, "[SpiralTask] A valid world must be specified!");
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
this.world = Bukkit.getWorld(fLocation.getWorldName());
|
||||
if (this.world == null) {
|
||||
P.p.log(Level.WARNING, "[SpiralTask] A valid world must be specified!");
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
this.x = (int) fLocation.getX();
|
||||
this.z = (int) fLocation.getZ();
|
||||
this.x = (int) fLocation.getX();
|
||||
this.z = (int) fLocation.getZ();
|
||||
|
||||
this.readyToGo = true;
|
||||
this.readyToGo = true;
|
||||
|
||||
// get this party started
|
||||
this.setTaskID(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, this, 2, 2));
|
||||
}
|
||||
// get this party started
|
||||
this.setTaskID(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, this, 2, 2));
|
||||
}
|
||||
|
||||
private static long now() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
private static long now() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/*
|
||||
* This is where the necessary work is done; you'll need to override this method with whatever you want
|
||||
* done at each chunk in the spiral pattern.
|
||||
* Return false if the entire task needs to be aborted, otherwise return true to continue.
|
||||
*/
|
||||
public abstract boolean work();
|
||||
/*
|
||||
* This is where the necessary work is done; you'll need to override this method with whatever you want
|
||||
* done at each chunk in the spiral pattern.
|
||||
* Return false if the entire task needs to be aborted, otherwise return true to continue.
|
||||
*/
|
||||
public abstract boolean work();
|
||||
|
||||
/*
|
||||
* Returns an FLocation pointing at the current chunk X and Z values.
|
||||
*/
|
||||
public final FLocation currentFLocation() {
|
||||
return new FLocation(world.getName(), x, z);
|
||||
}
|
||||
/*
|
||||
* Returns an FLocation pointing at the current chunk X and Z values.
|
||||
*/
|
||||
public final FLocation currentFLocation() {
|
||||
return new FLocation(world.getName(), x, z);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a Location pointing at the current chunk X and Z values.
|
||||
* note that the Location is at the corner of the chunk, not the center.
|
||||
*/
|
||||
public final Location currentLocation() {
|
||||
return new Location(world, FLocation.chunkToBlock(x), 65.0, FLocation.chunkToBlock(z));
|
||||
}
|
||||
/*
|
||||
* Returns a Location pointing at the current chunk X and Z values.
|
||||
* note that the Location is at the corner of the chunk, not the center.
|
||||
*/
|
||||
public final Location currentLocation() {
|
||||
return new Location(world, FLocation.chunkToBlock(x), 65.0, FLocation.chunkToBlock(z));
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns current chunk X and Z values.
|
||||
*/
|
||||
public final int getX() {
|
||||
return x;
|
||||
}
|
||||
/*
|
||||
* Returns current chunk X and Z values.
|
||||
*/
|
||||
public final int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Below are the guts of the class, which you normally wouldn't need to mess with.
|
||||
*/
|
||||
/*
|
||||
* Below are the guts of the class, which you normally wouldn't need to mess with.
|
||||
*/
|
||||
|
||||
public final int getZ() {
|
||||
return z;
|
||||
}
|
||||
public final int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public final void setTaskID(int ID) {
|
||||
if (ID == -1) {
|
||||
this.stop();
|
||||
}
|
||||
taskID = ID;
|
||||
}
|
||||
public final void setTaskID(int ID) {
|
||||
if (ID == -1) {
|
||||
this.stop();
|
||||
}
|
||||
taskID = ID;
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
if (!this.valid() || !readyToGo) {
|
||||
return;
|
||||
}
|
||||
public final void run() {
|
||||
if (!this.valid() || !readyToGo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this is set so it only does one iteration at a time, no matter how frequently the timer fires
|
||||
readyToGo = false;
|
||||
// this is set so it only does one iteration at a time, no matter how frequently the timer fires
|
||||
readyToGo = false;
|
||||
|
||||
// make sure we're still inside the specified radius
|
||||
if (!this.insideRadius()) {
|
||||
return;
|
||||
}
|
||||
// make sure we're still inside the specified radius
|
||||
if (!this.insideRadius()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// track this to keep one iteration from dragging on too long and possibly choking the system
|
||||
long loopStartTime = now();
|
||||
// track this to keep one iteration from dragging on too long and possibly choking the system
|
||||
long loopStartTime = now();
|
||||
|
||||
// keep going until the task has been running for 20ms or more, then stop to take a breather
|
||||
while (now() < loopStartTime + 20) {
|
||||
// run the primary task on the current X/Z coordinates
|
||||
if (!this.work()) {
|
||||
this.finish();
|
||||
return;
|
||||
}
|
||||
// keep going until the task has been running for 20ms or more, then stop to take a breather
|
||||
while (now() < loopStartTime + 20) {
|
||||
// run the primary task on the current X/Z coordinates
|
||||
if (!this.work()) {
|
||||
this.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// move on to next chunk in spiral
|
||||
if (!this.moveToNext()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// move on to next chunk in spiral
|
||||
if (!this.moveToNext()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ready for the next iteration to run
|
||||
readyToGo = true;
|
||||
}
|
||||
// ready for the next iteration to run
|
||||
readyToGo = true;
|
||||
}
|
||||
|
||||
// step through chunks in spiral pattern from center; returns false if we're done, otherwise returns true
|
||||
public final boolean moveToNext() {
|
||||
if (!this.valid()) {
|
||||
return false;
|
||||
}
|
||||
// step through chunks in spiral pattern from center; returns false if we're done, otherwise returns true
|
||||
public final boolean moveToNext() {
|
||||
if (!this.valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure we don't need to turn down the next leg of the spiral
|
||||
if (current < length) {
|
||||
current++;
|
||||
// make sure we don't need to turn down the next leg of the spiral
|
||||
if (current < length) {
|
||||
current++;
|
||||
|
||||
// if we're outside the radius, we're done
|
||||
if (!this.insideRadius()) {
|
||||
return false;
|
||||
}
|
||||
} else { // one leg/side of the spiral down...
|
||||
current = 0;
|
||||
isZLeg ^= true;
|
||||
// every second leg (between X and Z legs, negative or positive), length increases
|
||||
if (isZLeg) {
|
||||
isNeg ^= true;
|
||||
length++;
|
||||
}
|
||||
}
|
||||
// if we're outside the radius, we're done
|
||||
if (!this.insideRadius()) {
|
||||
return false;
|
||||
}
|
||||
} else { // one leg/side of the spiral down...
|
||||
current = 0;
|
||||
isZLeg ^= true;
|
||||
// every second leg (between X and Z legs, negative or positive), length increases
|
||||
if (isZLeg) {
|
||||
isNeg ^= true;
|
||||
length++;
|
||||
}
|
||||
}
|
||||
|
||||
// move one chunk further in the appropriate direction
|
||||
if (isZLeg) {
|
||||
z += (isNeg) ? -1 : 1;
|
||||
} else {
|
||||
x += (isNeg) ? -1 : 1;
|
||||
}
|
||||
// move one chunk further in the appropriate direction
|
||||
if (isZLeg) {
|
||||
z += (isNeg) ? -1 : 1;
|
||||
} else {
|
||||
x += (isNeg) ? -1 : 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean insideRadius() {
|
||||
boolean inside = current < limit;
|
||||
if (!inside) {
|
||||
this.finish();
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
public final boolean insideRadius() {
|
||||
boolean inside = current < limit;
|
||||
if (!inside) {
|
||||
this.finish();
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
// for successful completion
|
||||
public void finish() {
|
||||
// for successful completion
|
||||
public void finish() {
|
||||
// P.p.log("SpiralTask successfully completed!");
|
||||
this.stop();
|
||||
}
|
||||
this.stop();
|
||||
}
|
||||
|
||||
// we're done, whether finished or cancelled
|
||||
public final void stop() {
|
||||
if (!this.valid()) {
|
||||
return;
|
||||
}
|
||||
// we're done, whether finished or cancelled
|
||||
public final void stop() {
|
||||
if (!this.valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
readyToGo = false;
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskID);
|
||||
taskID = -1;
|
||||
}
|
||||
readyToGo = false;
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskID);
|
||||
taskID = -1;
|
||||
}
|
||||
|
||||
// is this task still valid/workable?
|
||||
public final boolean valid() {
|
||||
return taskID != -1;
|
||||
}
|
||||
// is this task still valid/workable?
|
||||
public final boolean valid() {
|
||||
return taskID != -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,86 +11,86 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class UtilFly {
|
||||
|
||||
public static void run() {
|
||||
if (!P.p.getConfig().getBoolean("enable-faction-flight"))
|
||||
return;
|
||||
public static void run() {
|
||||
if (!P.p.getConfig().getBoolean("enable-faction-flight"))
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> {
|
||||
for (FPlayer fp : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
if (fp.isFlying()) fp.checkIfNearbyEnemies();
|
||||
}
|
||||
}, 0, P.p.getConfig().getInt("fly-task-interval", 10));
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> {
|
||||
for (FPlayer fp : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
if (fp.isFlying()) fp.checkIfNearbyEnemies();
|
||||
}
|
||||
}, 0, P.p.getConfig().getInt("fly-task-interval", 10));
|
||||
}
|
||||
|
||||
public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) {
|
||||
if (!P.p.getConfig().getBoolean("enable-faction-flight"))
|
||||
return;
|
||||
public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) {
|
||||
if (!P.p.getConfig().getBoolean("enable-faction-flight"))
|
||||
return;
|
||||
|
||||
fp.getPlayer().setAllowFlight(fly);
|
||||
fp.getPlayer().setFlying(fly);
|
||||
fp.setFlying(fly);
|
||||
fp.getPlayer().setAllowFlight(fly);
|
||||
fp.getPlayer().setFlying(fly);
|
||||
fp.setFlying(fly);
|
||||
|
||||
|
||||
if (!silent) {
|
||||
if (!damage) {
|
||||
fp.msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled");
|
||||
} else {
|
||||
fp.msg(TL.COMMAND_FLY_DAMAGE);
|
||||
}
|
||||
}
|
||||
if (!silent) {
|
||||
if (!damage) {
|
||||
fp.msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled");
|
||||
} else {
|
||||
fp.msg(TL.COMMAND_FLY_DAMAGE);
|
||||
}
|
||||
}
|
||||
|
||||
setFallDamage(fp, fly, damage);
|
||||
}
|
||||
setFallDamage(fp, fly, damage);
|
||||
}
|
||||
|
||||
public static void checkFly(FPlayer me, Faction factionTo) {
|
||||
if (!P.p.getConfig().getBoolean("enable-faction-flight"))
|
||||
return;
|
||||
public static void checkFly(FPlayer me, Faction factionTo) {
|
||||
if (!P.p.getConfig().getBoolean("enable-faction-flight"))
|
||||
return;
|
||||
|
||||
if (me.isAdminBypassing() && me.isFlying())
|
||||
return;
|
||||
if (me.isAdminBypassing() && me.isFlying())
|
||||
return;
|
||||
|
||||
if (!me.isFlying()) {
|
||||
if (me.isAdminBypassing()) {
|
||||
UtilFly.setFly(me, true, false, false);
|
||||
return;
|
||||
}
|
||||
if (!me.isFlying()) {
|
||||
if (me.isAdminBypassing()) {
|
||||
UtilFly.setFly(me, true, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (factionTo == me.getFaction() && me.getPlayer().hasPermission("factions.fly")) {
|
||||
UtilFly.setFly(me, true, false, false);
|
||||
} else {
|
||||
Relation relationTo = factionTo.getRelationTo(me);
|
||||
if ((factionTo.isWilderness() && me.canflyinWilderness()) || (factionTo.isWarZone() && me.canflyinWarzone())
|
||||
|| (factionTo.isSafeZone() && me.canflyinSafezone()) || (relationTo == Relation.ENEMY && me.canflyinEnemy())
|
||||
|| (relationTo == Relation.ALLY && me.canflyinAlly()) || (relationTo == Relation.TRUCE && me.canflyinTruce())
|
||||
|| (relationTo == Relation.NEUTRAL && me.canflyinNeutral())) {
|
||||
UtilFly.setFly(me, true, false, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Relation relationTo = factionTo.getRelationTo(me);
|
||||
if ((factionTo.equals(me.getFaction()) && !me.getPlayer().hasPermission("factions.fly"))
|
||||
|| (factionTo.isWilderness() && !me.canflyinWilderness()) || (factionTo.isWarZone() && !me.canflyinWarzone())
|
||||
|| (factionTo.isSafeZone() && !me.canflyinSafezone()) || (relationTo == Relation.ENEMY && !me.canflyinEnemy())
|
||||
|| (relationTo == Relation.ALLY && !me.canflyinAlly()) || (relationTo == Relation.TRUCE && !me.canflyinTruce())
|
||||
|| (relationTo == Relation.NEUTRAL && !me.canflyinNeutral())) {
|
||||
UtilFly.setFly(me, false, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (factionTo == me.getFaction() && me.getPlayer().hasPermission("factions.fly")) {
|
||||
UtilFly.setFly(me, true, false, false);
|
||||
} else {
|
||||
Relation relationTo = factionTo.getRelationTo(me);
|
||||
if ((factionTo.isWilderness() && me.canflyinWilderness()) || (factionTo.isWarZone() && me.canflyinWarzone())
|
||||
|| (factionTo.isSafeZone() && me.canflyinSafezone()) || (relationTo == Relation.ENEMY && me.canflyinEnemy())
|
||||
|| (relationTo == Relation.ALLY && me.canflyinAlly()) || (relationTo == Relation.TRUCE && me.canflyinTruce())
|
||||
|| (relationTo == Relation.NEUTRAL && me.canflyinNeutral())) {
|
||||
UtilFly.setFly(me, true, false, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Relation relationTo = factionTo.getRelationTo(me);
|
||||
if ((factionTo.equals(me.getFaction()) && !me.getPlayer().hasPermission("factions.fly"))
|
||||
|| (factionTo.isWilderness() && !me.canflyinWilderness()) || (factionTo.isWarZone() && !me.canflyinWarzone())
|
||||
|| (factionTo.isSafeZone() && !me.canflyinSafezone()) || (relationTo == Relation.ENEMY && !me.canflyinEnemy())
|
||||
|| (relationTo == Relation.ALLY && !me.canflyinAlly()) || (relationTo == Relation.TRUCE && !me.canflyinTruce())
|
||||
|| (relationTo == Relation.NEUTRAL && !me.canflyinNeutral())) {
|
||||
UtilFly.setFly(me, false, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setFallDamage(FPlayer fp, boolean fly, boolean damage) {
|
||||
if (!fly) {
|
||||
if (!damage) {
|
||||
fp.sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", P.p.getConfig().getInt("fly-falldamage-cooldown", 3) + ""));
|
||||
}
|
||||
public static void setFallDamage(FPlayer fp, boolean fly, boolean damage) {
|
||||
if (!fly) {
|
||||
if (!damage) {
|
||||
fp.sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", P.p.getConfig().getInt("fly-falldamage-cooldown", 3) + ""));
|
||||
}
|
||||
|
||||
int cooldown = P.p.getConfig().getInt("fly-falldamage-cooldown", 3);
|
||||
if (cooldown > 0) {
|
||||
fp.setTakeFallDamage(false);
|
||||
Bukkit.getScheduler().runTaskLater(P.p, () -> fp.setTakeFallDamage(true), 20L * cooldown);
|
||||
}
|
||||
}
|
||||
}
|
||||
int cooldown = P.p.getConfig().getInt("fly-falldamage-cooldown", 3);
|
||||
if (cooldown > 0) {
|
||||
fp.setTakeFallDamage(false);
|
||||
Bukkit.getScheduler().runTaskLater(P.p, () -> fp.setTakeFallDamage(true), 20L * cooldown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,60 +9,60 @@ import java.util.*;
|
||||
|
||||
public class VisualizeUtil {
|
||||
|
||||
protected static Map<UUID, Set<Location>> playerLocations = new HashMap<>();
|
||||
protected static Map<UUID, Set<Location>> playerLocations = new HashMap<>();
|
||||
|
||||
public static Set<Location> getPlayerLocations(Player player) {
|
||||
return getPlayerLocations(player.getUniqueId());
|
||||
}
|
||||
public static Set<Location> getPlayerLocations(Player player) {
|
||||
return getPlayerLocations(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static Set<Location> getPlayerLocations(UUID uuid) {
|
||||
Set<Location> ret = playerLocations.computeIfAbsent(uuid, k -> new HashSet<>());
|
||||
return ret;
|
||||
}
|
||||
public static Set<Location> getPlayerLocations(UUID uuid) {
|
||||
Set<Location> ret = playerLocations.computeIfAbsent(uuid, k -> new HashSet<>());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void addLocation(Player player, Location location, Material type, byte data) {
|
||||
getPlayerLocations(player).add(location);
|
||||
player.sendBlockChange(location, type, data);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void addLocation(Player player, Location location, Material type, byte data) {
|
||||
getPlayerLocations(player).add(location);
|
||||
player.sendBlockChange(location, type, data);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void addLocation(Player player, Location location, Material material) {
|
||||
getPlayerLocations(player).add(location);
|
||||
player.sendBlockChange(location, material, (byte) 0);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void addLocation(Player player, Location location, Material material) {
|
||||
getPlayerLocations(player).add(location);
|
||||
player.sendBlockChange(location, material, (byte) 0);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void addLocations(Player player, Collection<Location> locations, Material material) {
|
||||
Set<Location> ploc = getPlayerLocations(player);
|
||||
for (Location location : locations) {
|
||||
ploc.add(location);
|
||||
player.sendBlockChange(location, material, (byte) 0);
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void addLocations(Player player, Collection<Location> locations, Material material) {
|
||||
Set<Location> ploc = getPlayerLocations(player);
|
||||
for (Location location : locations) {
|
||||
ploc.add(location);
|
||||
player.sendBlockChange(location, material, (byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void addBlocks(Player player, Collection<Block> blocks, Material material) {
|
||||
Set<Location> ploc = getPlayerLocations(player);
|
||||
for (Block block : blocks) {
|
||||
Location location = block.getLocation();
|
||||
ploc.add(location);
|
||||
player.sendBlockChange(location, material, (byte) 0);
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void addBlocks(Player player, Collection<Block> blocks, Material material) {
|
||||
Set<Location> ploc = getPlayerLocations(player);
|
||||
for (Block block : blocks) {
|
||||
Location location = block.getLocation();
|
||||
ploc.add(location);
|
||||
player.sendBlockChange(location, material, (byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void clear(Player player) {
|
||||
Set<Location> locations = getPlayerLocations(player);
|
||||
if (locations == null) {
|
||||
return;
|
||||
}
|
||||
for (Location location : locations) {
|
||||
Block block = location.getWorld().getBlockAt(location);
|
||||
player.sendBlockChange(location, block.getType(), block.getData());
|
||||
}
|
||||
locations.clear();
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void clear(Player player) {
|
||||
Set<Location> locations = getPlayerLocations(player);
|
||||
if (locations == null) {
|
||||
return;
|
||||
}
|
||||
for (Location location : locations) {
|
||||
Block block = location.getWorld().getBlockAt(location);
|
||||
player.sendBlockChange(location, block.getType(), block.getData());
|
||||
}
|
||||
locations.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,34 +6,34 @@ import com.massivecraft.factions.zcore.util.TL;
|
||||
|
||||
public class WarmUpUtil {
|
||||
|
||||
/**
|
||||
* @param player The player to notify.
|
||||
* @param translationKey The translation key used for notifying.
|
||||
* @param action The action, inserted into the notification message.
|
||||
* @param runnable The task to run after the delay. If the delay is 0, the task is instantly ran.
|
||||
* @param delay The time used, in seconds, for the delay.
|
||||
* <p>
|
||||
* note: for translations: %s = action, %d = delay
|
||||
*/
|
||||
public static void process(final FPlayer player, Warmup warmup, TL translationKey, String action, final Runnable runnable, long delay) {
|
||||
if (delay > 0) {
|
||||
if (player.isWarmingUp()) {
|
||||
player.msg(TL.WARMUPS_ALREADY);
|
||||
} else {
|
||||
player.msg(translationKey.format(action, delay));
|
||||
int id = P.p.getServer().getScheduler().runTaskLater(P.p, () -> {
|
||||
player.stopWarmup();
|
||||
runnable.run();
|
||||
}, delay * 20).getTaskId();
|
||||
player.addWarmup(warmup, id);
|
||||
}
|
||||
} else {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param player The player to notify.
|
||||
* @param translationKey The translation key used for notifying.
|
||||
* @param action The action, inserted into the notification message.
|
||||
* @param runnable The task to run after the delay. If the delay is 0, the task is instantly ran.
|
||||
* @param delay The time used, in seconds, for the delay.
|
||||
* <p>
|
||||
* note: for translations: %s = action, %d = delay
|
||||
*/
|
||||
public static void process(final FPlayer player, Warmup warmup, TL translationKey, String action, final Runnable runnable, long delay) {
|
||||
if (delay > 0) {
|
||||
if (player.isWarmingUp()) {
|
||||
player.msg(TL.WARMUPS_ALREADY);
|
||||
} else {
|
||||
player.msg(translationKey.format(action, delay));
|
||||
int id = P.p.getServer().getScheduler().runTaskLater(P.p, () -> {
|
||||
player.stopWarmup();
|
||||
runnable.run();
|
||||
}, delay * 20).getTaskId();
|
||||
player.addWarmup(warmup, id);
|
||||
}
|
||||
} else {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Warmup {
|
||||
HOME, WARP, FLIGHT, BANNER, CHECKPOINT
|
||||
}
|
||||
public enum Warmup {
|
||||
HOME, WARP, FLIGHT, BANNER, CHECKPOINT
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1318,7 +1318,8 @@ public enum XMaterial {
|
||||
*/
|
||||
public static String getExactMajorVersion(String version) {
|
||||
// getBukkitVersion()
|
||||
if (version.contains("SNAPSHOT") || version.contains("-R")) version = version.substring(0, version.indexOf("-"));
|
||||
if (version.contains("SNAPSHOT") || version.contains("-R"))
|
||||
version = version.substring(0, version.indexOf("-"));
|
||||
// getVersion()
|
||||
if (version.contains("git")) version = version.substring(version.indexOf("MC:") + 4).replace(")", "");
|
||||
if (version.split(Pattern.quote(".")).length > 2) version = version.substring(0, version.lastIndexOf("."));
|
||||
@@ -1334,7 +1335,8 @@ public enum XMaterial {
|
||||
*/
|
||||
private static MinecraftVersion valueOfVersion(String version) {
|
||||
version = getExactMajorVersion(version);
|
||||
if (version.equals("1.10") || version.equals("1.11") || version.equals("1.12")) return MinecraftVersion.VERSION_1_9;
|
||||
if (version.equals("1.10") || version.equals("1.11") || version.equals("1.12"))
|
||||
return MinecraftVersion.VERSION_1_9;
|
||||
version = version.replace(".", "_");
|
||||
if (!version.startsWith("VERSION_")) version = "VERSION_" + version;
|
||||
String check = version;
|
||||
|
||||
Reference in New Issue
Block a user