Code Overhaul + Minor Fixes

This commit is contained in:
Driftay 2019-04-16 09:02:31 -04:00
parent 7f53b52d1c
commit 8c6107859e
21 changed files with 116 additions and 208 deletions

View File

@ -19,7 +19,6 @@ public class CmdAdmin extends FCommand {
this.aliases.add("setleader");
this.requiredArgs.add("player name");
//this.optionalArgs.put("", "");
this.permission = Permission.ADMIN.node;
this.disableOnLock = true;

View File

@ -51,12 +51,7 @@ public class CmdCheckpoint extends FCommand {
if (checkfaction.getId().equals(Factions.getInstance().getWilderness().getId()) || checkfaction.getId().equals(fme.getFaction().getId())) {
fme.msg(TL.COMMAND_CHECKPOINT_GO);
this.doWarmUp(WarmUpUtil.Warmup.CHECKPOINT, TL.WARMUPS_NOTIFY_TELEPORT, "Checkpoint", new Runnable() {
@Override
public void run() {
fme.getPlayer().teleport(fme.getFaction().getCheckpoint());
}
}, this.p.getConfig().getLong("warmups.f-checkpoint", 0));
this.doWarmUp(WarmUpUtil.Warmup.CHECKPOINT, TL.WARMUPS_NOTIFY_TELEPORT, "Checkpoint", () -> fme.getPlayer().teleport(fme.getFaction().getCheckpoint()), this.p.getConfig().getLong("warmups.f-checkpoint", 0));
} else {
fme.msg(TL.COMMAND_CHECKPOINT_CLAIMED);
}

View File

@ -81,12 +81,7 @@ public class CmdDisband extends FCommand {
if (!disbandMap.containsKey(me.getUniqueId().toString()) && faction.getTnt() > 0) {
msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));
disbandMap.put(me.getUniqueId().toString(), faction.getId());
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
disbandMap.remove(me.getUniqueId().toString());
}
}, 200L);
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, () -> disbandMap.remove(me.getUniqueId().toString()), 200L);
} else if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) {
if (SavageFactions.plugin.getConfig().getBoolean("faction-disband-broadcast", true)) {
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {

View File

@ -66,14 +66,11 @@ public class CmdFWarp extends FCommand {
}
final FPlayer fPlayer = fme;
final UUID uuid = fme.getPlayer().getUniqueId();
this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation());
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
}
this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation());
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
}
}, this.p.getConfig().getLong("warmups.f-warp", 0));
} else {

View File

@ -123,21 +123,18 @@ public class CmdHome extends FCommand {
return;
}
this.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", new Runnable() {
@Override
public void run() {
// Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled) {
List<Location> smokeLocations = new ArrayList<>();
smokeLocations.add(loc);
smokeLocations.add(loc.add(0, 1, 0));
smokeLocations.add(CmdHome.this.myFaction.getHome());
smokeLocations.add(CmdHome.this.myFaction.getHome().clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
}
CmdHome.this.me.teleport(CmdHome.this.myFaction.getHome());
this.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", () -> {
// Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled) {
List<Location> smokeLocations = new ArrayList<>();
smokeLocations.add(loc);
smokeLocations.add(loc.add(0, 1, 0));
smokeLocations.add(CmdHome.this.myFaction.getHome());
smokeLocations.add(CmdHome.this.myFaction.getHome().clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
}
CmdHome.this.me.teleport(CmdHome.this.myFaction.getHome());
}, this.p.getConfig().getLong("warmups.f-home", 0));
}

View File

@ -52,43 +52,32 @@ public class CmdList extends FCommand {
// remove exempt factions
if (fme != null && fme.getPlayer() != null && !fme.getPlayer().hasPermission("factions.show.bypassexempt")) {
List<String> exemptFactions = SavageFactions.plugin.getConfig().getStringList("show-exempt");
Iterator<Faction> factionIterator = factionList.iterator();
while (factionIterator.hasNext()) {
Faction next = factionIterator.next();
if (exemptFactions.contains(next.getTag()))
factionIterator.remove();
}
factionList.removeIf(next -> exemptFactions.contains(next.getTag()));
}
// Sort by total followers first
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
Collections.sort(factionList, (f1, f2) -> {
int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
// Then sort by how many members are online now
Collections.sort(factionList, new Comparator<Faction>() {
@Override
public int compare(Faction f1, Faction f2) {
int f1Size = f1.getFPlayersWhereOnline(true).size();
int f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
Collections.sort(factionList, (f1, f2) -> {
int f1Size = f1.getFPlayersWhereOnline(true).size();
int f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
ArrayList<String> lines = new ArrayList<>();

View File

@ -30,7 +30,6 @@ public class CmdReload extends FCommand {
SavageFactions.plugin.reloadConfig();
SavageFactions.plugin.changeItemIDSInConfig();
SavageFactions.plugin.loadLang();
int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]);
if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) {

View File

@ -17,9 +17,8 @@ public class CmdSeeChunk extends FCommand {
//Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn.
public static HashMap<String, Boolean> seeChunkMap = new HashMap<>();
Long interval = 10L;
Long interval;
private boolean useParticles;
private int length;
private ParticleEffect effect;
private int taskID = -1;
@ -72,18 +71,15 @@ public class CmdSeeChunk extends FCommand {
}
private void startTask() {
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
Iterator<String> itr = seeChunkMap.keySet().iterator();
while (itr.hasNext()) {
Object nameObject = itr.next();
String name = nameObject + "";
Player player = Bukkit.getPlayer(name);
showBorders(player);
}
manageTask();
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, () -> {
Iterator<String> itr = seeChunkMap.keySet().iterator();
while (itr.hasNext()) {
Object nameObject = itr.next();
String name = nameObject + "";
Player player = Bukkit.getPlayer(name);
showBorders(player);
}
manageTask();
}, 0, interval);
}

View File

@ -39,7 +39,6 @@ public class CmdShowClaims extends FCommand {
chunks.setLength(0);
}
}
sendMessage("");
}

View File

@ -99,7 +99,7 @@ public class CmdTnt extends FCommand {
return;
}
if (fme.getFaction().getTnt() < amount) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
return;
}
int fullStacks = amount / 64;

View File

@ -30,16 +30,9 @@ public class CmdTpBanner extends FCommand {
return;
}
final FactionsPlayerListener fpl = new FactionsPlayerListener();
if (FactionsBlockListener.bannerLocations.containsKey(fme.getTag())) {
fme.msg(TL.COMMAND_TPBANNER_SUCCESS);
this.doWarmUp(WarmUpUtil.Warmup.BANNER, TL.WARMUPS_NOTIFY_TELEPORT, "Banner", new Runnable() {
@Override
public void run() {
me.teleport(FactionsBlockListener.bannerLocations.get(fme.getTag()));
}
}, this.p.getConfig().getLong("warmups.f-banner", 0));
this.doWarmUp(WarmUpUtil.Warmup.BANNER, TL.WARMUPS_NOTIFY_TELEPORT, "Banner", () -> me.teleport(FactionsBlockListener.bannerLocations.get(fme.getTag())), this.p.getConfig().getLong("warmups.f-banner", 0));
} else {
fme.msg(TL.COMMAND_TPBANNER_NOTSET);
}

View File

@ -113,27 +113,24 @@ public class EngineDynmap {
}
// Shedule non thread safe sync at the end!
Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, () -> {
final Map<String, TempMarker> homes = createHomes();
final Map<String, TempAreaMarker> areas = createAreas();
final Map<String, Set<String>> playerSets = createPlayersets();
final Map<String, TempMarker> homes = createHomes();
final Map<String, TempAreaMarker> areas = createAreas();
final Map<String, Set<String>> playerSets = createPlayersets();
if (!updateCore()) {
return;
}
// createLayer() is thread safe but it makes use of fields set in updateCore() so we must have it after.
if (!updateLayer(createLayer())) {
return;
}
updateHomes(homes);
updateAreas(areas);
updatePlayersets(playerSets);
if (!updateCore()) {
return;
}
// createLayer() is thread safe but it makes use of fields set in updateCore() so we must have it after.
if (!updateLayer(createLayer())) {
return;
}
updateHomes(homes);
updateAreas(areas);
updatePlayersets(playerSets);
}, 100L, 100L);
}

View File

@ -332,12 +332,7 @@ public class FactionsBlockListener implements Listener {
as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not
final ArmorStand armorStand = as;
final String tag = fme.getTag();
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
bannerCooldownMap.remove(tag);
}
}, Long.parseLong(bannerCooldown + ""));
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + ""));
final Block banner = e.getBlockPlaced();
final Material bannerType = banner.getType();
final Faction bannerFaction = fme.getFaction();
@ -345,39 +340,33 @@ public class FactionsBlockListener implements Listener {
// e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ENTITY_LIGHTNING_IMPACT,2.0F,0.5F);
final int radius = SavageFactions.plugin.getConfig().getInt("fbanners.Banner-Effect-Radius");
final List<String> effects = SavageFactions.plugin.getConfig().getStringList("fbanners.Effects");
final int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
final int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, () -> {
for (Entity e : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), radius, 255, radius)) {
if (e instanceof Player) {
Player player = (Player) e;
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
if (fplayer.getFaction() == bannerFaction) {
for (String effect : effects) {
String[] components = effect.split(":");
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1])));
}
ParticleEffect.LAVA.display(1, 1, 1, 1, 10, banner.getLocation(), 16);
ParticleEffect.FLAME.display(1, 1, 1, 1, 10, banner.getLocation(), 16);
for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), radius, 255, radius)) {
if (e1 instanceof Player) {
Player player = (Player) e1;
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
if (fplayer.getFaction() == bannerFaction) {
for (String effect : effects) {
String[] components = effect.split(":");
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1])));
}
ParticleEffect.LAVA.display(1, 1, 1, 1, 10, banner.getLocation(), 16);
ParticleEffect.FLAME.display(1, 1, 1, 1, 10, banner.getLocation(), 16);
if (banner.getType() != bannerType) {
banner.setType(bannerType);
}
if (banner.getType() != bannerType) {
banner.setType(bannerType);
}
}
}
}
}, 0L, 20L);
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
banner.setType(Material.AIR);
as.remove();
banner.getWorld().strikeLightningEffect(banner.getLocation());
Bukkit.getScheduler().cancelTask(affectorTask);
bannerLocations.remove(bannerFaction.getTag());
}
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, () -> {
banner.setType(Material.AIR);
as.remove();
banner.getWorld().strikeLightningEffect(banner.getLocation());
Bukkit.getScheduler().cancelTask(affectorTask);
bannerLocations.remove(bannerFaction.getTag());
}, Long.parseLong(bannerTime + ""));
} else {
fme.msg(TL.WARBANNER_INVALIDLOC);

View File

@ -196,14 +196,11 @@ public class FactionsChatListener implements Listener {
}
private void doWarmup(final String warp, final FPlayer fme) {
WarmUpUtil.process(fme, WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warp, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(fme.getPlayer().getUniqueId());
if (player != null) {
player.teleport(fme.getFaction().getWarp(warp).getLocation());
fme.msg(TL.COMMAND_FWARP_WARPED, warp);
}
WarmUpUtil.process(fme, WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warp, () -> {
Player player = Bukkit.getPlayer(fme.getPlayer().getUniqueId());
if (player != null) {
player.teleport(fme.getFaction().getWarp(warp).getLocation());
fme.msg(TL.COMMAND_FWARP_WARPED, warp);
}
}, SavageFactions.plugin.getConfig().getLong("warmups.f-warp", 0));
}

View File

@ -296,12 +296,9 @@ public class FactionsPlayerListener implements Listener {
me.login(); // set kills / deaths
// Check for Faction announcements. Let's delay this so they actually see it.
Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
if (me.isOnline()) {
me.getFaction().sendUnreadAnnouncements(me);
}
Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, () -> {
if (me.isOnline()) {
me.getFaction().sendUnreadAnnouncements(me);
}
}, 33L); // Don't ask me why.
@ -322,13 +319,7 @@ public class FactionsPlayerListener implements Listener {
fallMap.put(me.getPlayer(), false);
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
fallMap.remove(me.getPlayer());
}
}, 180L);
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, () -> fallMap.remove(me.getPlayer()), 180L);
if (me.isSpyingChat() && !player.hasPermission(Permission.CHATSPY.node)) {

View File

@ -45,12 +45,9 @@ public class FTeamWrapper {
if (updating.add(faction)) {
Bukkit.getScheduler().runTask(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
updating.remove(faction);
applyUpdates(faction);
}
Bukkit.getScheduler().runTask(SavageFactions.plugin, () -> {
updating.remove(faction);
applyUpdates(faction);
});
}
}

View File

@ -21,12 +21,9 @@ public class WarmUpUtil {
player.msg(TL.WARMUPS_ALREADY);
} else {
player.msg(translationKey.format(action, delay));
int id = SavageFactions.plugin.getServer().getScheduler().runTaskLater(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
player.stopWarmup();
runnable.run();
}
int id = SavageFactions.plugin.getServer().getScheduler().runTaskLater(SavageFactions.plugin, () -> {
player.stopWarmup();
runnable.run();
}, delay * 20).getTaskId();
player.addWarmup(warmup, id);
}

View File

@ -102,13 +102,10 @@ public class WarpGUI implements InventoryHolder, FactionGUI {
} else {
fme.setEnteringPassword(true, warp);
fme.msg(TL.COMMAND_FWARP_PASSWORD_REQUIRED);
Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
if (fme.isEnteringPassword()) {
fme.msg(TL.COMMAND_FWARP_PASSWORD_TIMEOUT);
fme.setEnteringPassword(false, "");
}
Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, () -> {
if (fme.isEnteringPassword()) {
fme.msg(TL.COMMAND_FWARP_PASSWORD_TIMEOUT);
fme.setEnteringPassword(false, "");
}
}, SavageFactions.plugin.getConfig().getInt("fwarp-gui.password-timeout", 5) * 20);
}
@ -116,14 +113,11 @@ public class WarpGUI implements InventoryHolder, FactionGUI {
}
private void doWarmup(final String warp) {
WarmUpUtil.process(fme, WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warp, new Runnable() {
@Override
public void run() {
Player player = Bukkit.getPlayer(fme.getPlayer().getUniqueId());
if (player != null) {
player.teleport(fme.getFaction().getWarp(warp).getLocation());
fme.msg(TL.COMMAND_FWARP_WARPED, warp);
}
WarmUpUtil.process(fme, WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warp, () -> {
Player player = Bukkit.getPlayer(fme.getPlayer().getUniqueId());
if (player != null) {
player.teleport(fme.getFaction().getWarp(warp).getLocation());
fme.msg(TL.COMMAND_FWARP_WARPED, warp);
}
}, SavageFactions.plugin.getConfig().getLong("warmups.f-warp", 0));
}

View File

@ -278,12 +278,7 @@ public abstract class MPlugin extends JavaPlugin {
}
if (async) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
command.execute(sender, args);
}
});
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> command.execute(sender, args));
} else {
command.execute(sender, args);
}

View File

@ -873,12 +873,7 @@ public abstract class MemoryFPlayer implements FPlayer {
// Short task so we're just doing it in method. Not clean but eh.
if (cooldown > 0) {
setTakeFallDamage(false);
Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
setTakeFallDamage(true);
}
}, 20L * cooldown);
Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, () -> setTakeFallDamage(true), 20L * cooldown);
}
}

View File

@ -80,17 +80,14 @@ public class DiscUtil {
lock.unlock();
}
} else {
Bukkit.getScheduler().runTaskAsynchronously(SavageFactions.plugin, new Runnable() {
@Override
public void run() {
lock.lock();
try {
write(file, content);
} catch (IOException e) {
e.printStackTrace();
} finally {
lock.unlock();
}
Bukkit.getScheduler().runTaskAsynchronously(SavageFactions.plugin, () -> {
lock.lock();
try {
write(file, content);
} catch (IOException e) {
e.printStackTrace();
} finally {
lock.unlock();
}
});
}