New Shop Config Format With Help, Removed Useless Code FactionsBlockListener Block Break Revamp, F Wild Revamp (DroppingAnvil) & Alot I can't remember xD

This commit is contained in:
Driftay
2020-04-04 05:09:05 -04:00
parent 0aeadcf0d0
commit d79b93d6c5
90 changed files with 576 additions and 560 deletions

View File

@@ -1,12 +0,0 @@
package com.massivecraft.factions.util;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.InventoryHolder;
public interface FactionGUI extends InventoryHolder {
void onClick(int slot, ClickType action);
void build();
}

View File

@@ -1,116 +0,0 @@
package com.massivecraft.factions.util;
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.FactionsPlugin;
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.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class FactionWarpsFrame {
private Gui gui;
private ConfigurationSection section;
public FactionWarpsFrame(final Faction f) {
this.section = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fwarp-gui");
this.gui = new Gui(FactionsPlugin.getInstance(), section.getInt("rows", 3), FactionsPlugin.getInstance().color(this.section.getString("name").replace("{faction}", f.getTag())));
}
public void buildGUI(final FPlayer fplayer) {
final PaginatedPane pane = new PaginatedPane(0, 0, 9, this.gui.getRows());
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)));
slots.forEach(slot -> GUIItems.set(slot, new GuiItem(XMaterial.AIR.parseItem())));
for (final Map.Entry<String, LazyLocation> warp : fplayer.getFaction().getWarps().entrySet()) {
if (slots.size() < fplayer.getFaction().getWarps().entrySet().size()) {
slots.add(slots.get(slots.size() - 1) + 1);
FactionsPlugin.instance.log("Automatically setting F WARP GUI slot since slot not specified. Head config.yml and add more entries in warp-slots section.");
}
GUIItems.set(slots.get(count), new GuiItem(buildWarpAsset(warp, fplayer.getFaction()), e -> {
e.setCancelled(true);
fplayer.getPlayer().closeInventory();
if (!fplayer.getFaction().hasWarpPassword(warp.getKey())) {
if (transact(fplayer)) {
doWarmup(warp.getKey(), fplayer);
}
} else {
fplayer.setEnteringPassword(true, warp.getKey());
fplayer.msg(TL.COMMAND_FWARP_PASSWORD_REQUIRED);
Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> {
if (fplayer.isEnteringPassword()) {
fplayer.msg(TL.COMMAND_FWARP_PASSWORD_TIMEOUT);
fplayer.setEnteringPassword(false, "");
}
}, FactionsPlugin.getInstance().getConfig().getInt("fwarp-gui.password-timeout", 5) * 20);
}
}));
++count;
}
pane.populateWithGuiItems(GUIItems);
gui.addPane(pane);
gui.update();
gui.show(fplayer.getPlayer());
}
private ItemStack buildWarpAsset(final Map.Entry<String, LazyLocation> warp, final Faction faction) {
final ConfigurationSection config = this.section.getConfigurationSection("warp-item");
final ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).get().parseItem();
final ItemMeta meta = item.getItemMeta();
meta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().replacePlaceholders(config.getStringList("Lore"), new Placeholder("{warp-protected}", faction.hasWarpPassword(warp.getKey()) ? "Enabled" : "Disabled"), new Placeholder("{warp-cost}", FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) ? Integer.toString(FactionsPlugin.getInstance().getConfig().getInt("warp-cost.warp", 5)) : "Disabled"))));
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name").replace("{warp}", warp.getKey())));
item.setItemMeta(meta);
return item;
}
private ItemStack buildDummyItem() {
final ConfigurationSection config = this.section.getConfigurationSection("dummy-item");
final ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).get().parseItem();
final ItemMeta meta = item.getItemMeta();
meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore")));
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name")));
item.setItemMeta(meta);
return item;
}
private void doWarmup(final String warp, FPlayer fme) {
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);
}
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-warp", 0));
}
private boolean transact(FPlayer player) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing())
return true;
double cost = FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.warp", 5);
if (!Econ.shouldBeUsed() || cost == 0.0 || player.isAdminBypassing()) return true;
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && player.hasFaction()) {
return Econ.modifyMoney(player.getFaction(), -cost, TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
} else {
return Econ.modifyMoney(player, -cost, TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
}
}
}

View File

@@ -62,7 +62,7 @@ public class InventoryUtil {
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Cannot into itemstacksz!", e);
throw new IllegalStateException("Cannot convert into itemstacks!", e);
}
}

View File

@@ -1,5 +1,10 @@
package com.massivecraft.factions.util.Particles;
package com.massivecraft.factions.util;
/**
* Factions - Developed by Driftay.
* All rights reserved 2020.
* Creation Date: 4/4/2020
*/
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Color;
@@ -1595,4 +1600,4 @@ public enum ParticleEffect {
}
}
}
}
}

View File

@@ -1,59 +0,0 @@
package com.massivecraft.factions.util.Particles;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Particle;
public enum Particles {
// Gotta use Strings or runtime errors on 1.8, the Particle class does not exist
CLOUD(ParticleEffect.CLOUD, "CLOUD"),
REDSTONE(ParticleEffect.REDSTONE, "REDSTONE"),
NOTE(ParticleEffect.NOTE, "NOTE");
private ParticleEffect sub18;
private String over19;
Particles(ParticleEffect sub18, String over19) {
this.sub18 = sub18;
this.over19 = over19;
}
public void displayAtLocation(Location location, int amt) {
if (FactionsPlugin.getInstance().useNonPacketParticles) {
// 1.9+ based servers will use the built in particleAPI instead of packet based.
// any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working.
// So setting the amount to 0 spawns 1 in the precise location
location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0);
} else {
sub18.display((float) 0, (float) 0, (float) 0, (float) 0, amt, location, 16);
}
}
public void displayAtLocation(Location location, int amt, ParticleEffect.OrdinaryColor color) {
if (FactionsPlugin.getInstance().useNonPacketParticles) {
// 1.9-1.11 & 1.13+ based servers will use the built in particleAPI instead of packet based.
// any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working.
// So setting the amount to 0 spawns 1 in the precise location
// Gotta do this so colorable ones have their data :FactionsPlugin
if (this == Particles.REDSTONE || this == Particles.CLOUD || this == Particles.NOTE) {
if (FactionsPlugin.getInstance().mc112) {
location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0);
} else {
location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0, new Particle.DustOptions(Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), 1));
}
} else {
location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0);
}
} else {
sub18.display(color, location, 16);
}
}
}

View File

@@ -1,5 +1,10 @@
package com.massivecraft.factions.util.Particles;
package com.massivecraft.factions.util;
/**
* Factions - Developed by Driftay.
* All rights reserved 2020.
* Creation Date: 4/4/2020
*/
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor;
@@ -605,4 +610,4 @@ public final class ReflectionUtils {
return reference;
}
}
}
}

View File

@@ -1,108 +0,0 @@
package com.massivecraft.factions.util;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Factions - Developed by Driftay.
* All rights reserved 2020.
* Creation Date: 1/30/2020
*/
public class TimeUtil {
public static long parseDateDiff(String time, boolean future) throws Exception {
Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)?", 2);
Matcher m = timePattern.matcher(time);
int years = 0;
int months = 0;
int weeks = 0;
int days = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
boolean found = false;
while (m.find()) {
if (m.group() != null) {
if (m.group().isEmpty()) continue;
for (int i = 0; i < m.groupCount(); ++i) {
if (m.group(i) != null && !m.group(i).isEmpty()) {
found = true;
break;
}
}
if (!found) continue;
if (m.group(1) != null && !m.group(1).isEmpty()) years = Integer.parseInt(m.group(1));
if (m.group(2) != null && !m.group(2).isEmpty()) months = Integer.parseInt(m.group(2));
if (m.group(3) != null && !m.group(3).isEmpty()) weeks = Integer.parseInt(m.group(3));
if (m.group(4) != null && !m.group(4).isEmpty()) days = Integer.parseInt(m.group(4));
if (m.group(5) != null && !m.group(5).isEmpty()) hours = Integer.parseInt(m.group(5));
if (m.group(6) != null && !m.group(6).isEmpty()) minutes = Integer.parseInt(m.group(6));
if (m.group(7) != null && !m.group(7).isEmpty()) {
seconds = Integer.parseInt(m.group(7));
break;
}
break;
}
}
if (!found) throw new Exception("Illegal Date");
if (years > 20) throw new Exception("Illegal Date");
Calendar c = new GregorianCalendar();
if (years > 0) c.add(Calendar.YEAR, years * (future ? 1 : -1));
if (months > 0) c.add(Calendar.MONTH, months * (future ? 1 : -1));
if (weeks > 0) c.add(Calendar.WEEK_OF_YEAR, weeks * (future ? 1 : -1));
if (days > 0) c.add(Calendar.DATE, days * (future ? 1 : -1));
if (hours > 0) c.add(Calendar.HOUR_OF_DAY, hours * (future ? 1 : -1));
if (minutes > 0) c.add(Calendar.MINUTE, minutes * (future ? 1 : -1));
if (seconds > 0) c.add(Calendar.SECOND, seconds * (future ? 1 : -1));
System.out.println("current: " + c.getTimeInMillis() + " Time: " + System.currentTimeMillis() + " Form: " + formatTime(c.getTimeInMillis() / 1000L));
return c.getTimeInMillis() / 1000L;
}
public static String formatDifference(long time) {
if (time == 0L) return "Never";
long day = TimeUnit.SECONDS.toDays(time);
long hours = TimeUnit.SECONDS.toHours(time) - day * 24L;
long minutes = TimeUnit.SECONDS.toMinutes(time) - TimeUnit.SECONDS.toHours(time) * 60L;
long seconds = TimeUnit.SECONDS.toSeconds(time) - TimeUnit.SECONDS.toMinutes(time) * 60L;
StringBuilder sb = new StringBuilder();
if (day > 0L) sb.append(day).append((day == 1L) ? "day" : "days").append(" ");
if (hours > 0L) sb.append(hours).append((hours == 1L) ? "h" : "h").append(" ");
if (minutes > 0L) sb.append(minutes).append((minutes == 1L) ? "m" : "m").append(" ");
if (seconds > 0L) sb.append(seconds).append((seconds == 1L) ? "s" : "s");
String diff = sb.toString().trim();
return diff.isEmpty() ? "Now" : diff;
}
public static String formatTime(long time) {
if (time == System.currentTimeMillis()) return "Now";
if (time == -1L) return "Never";
return formatDifference(time - System.currentTimeMillis() / 1000L);
}
}

View File

@@ -1,49 +0,0 @@
package com.massivecraft.factions.util;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Updater {
public static double currentVersion = 1.1;
public static void updateIfNeeded(FileConfiguration conf) {
double version = conf.getDouble("Config-Version", 0);
//Previous version
if (version == 0) {
//Instructions for this configuration to be updated to current
FactionsPlugin.getInstance().log("Your config.yml is pre-versioning so we are going to assign it version 1.0 \n Please regenerate your config.yml if you run into any errors relating to config.");
conf.set("Config-Version", 1.0);
version = 1.0;
}
if (version == 1.0) {
FactionsPlugin.getInstance().log("Updating config from version 1.0 to 1.1");
FactionsPlugin.getInstance().log("Adding randomization support for f missions...");
conf.set("Randomization.Enabled", false);
conf.set("Randomization.Start-Item.Allowed.Name", "&aStart!");
conf.set("Randomization.Start-Item.Allowed.Material", "GREEN_STAINED_GLASS_PANE");
List<String> lore = new ArrayList<>();
lore.add("&aStart a new mission!");
conf.set("Randomization.Start-Item.Allowed.Lore", lore);
conf.set("Randomization.Start-Item.Disallowed.Name", "&4Cannot start new mission");
conf.set("Randomization.Start-Item.Disallowed.Material", "GRAY_STAINED_GLASS_PANE");
lore.clear();
lore.add("&4%reason%");
conf.set("Randomization.Start-Item.Disallowed.Lore", lore);
conf.set("Randomization.Start-Item.Slot", 28);
conf.set("Config-Version", 1.1);
currentVersion = 1.1;
}
//End with save + reload
try {
conf.save(new File("plugins/Factions/config.yml"));
FactionsPlugin.getInstance().reloadConfig();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,4 +1,4 @@
package com.massivecraft.factions.util;
package com.massivecraft.factions.util.adapters;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;

View File

@@ -1,7 +1,8 @@
package com.massivecraft.factions.util;
package com.massivecraft.factions.util.adapters;
import com.google.gson.*;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.InventoryUtil;
import org.bukkit.inventory.Inventory;
import java.lang.reflect.Type;

View File

@@ -1,4 +1,4 @@
package com.massivecraft.factions.util;
package com.massivecraft.factions.util.adapters;
import com.google.gson.*;
import com.massivecraft.factions.FactionsPlugin;

View File

@@ -1,4 +1,4 @@
package com.massivecraft.factions.util;
package com.massivecraft.factions.util.adapters;
import com.google.gson.*;
import com.massivecraft.factions.FLocation;

View File

@@ -1,7 +1,8 @@
package com.massivecraft.factions.util;
package com.massivecraft.factions.util.adapters;
import com.google.gson.*;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.LazyLocation;
import java.lang.reflect.Type;
import java.util.logging.Level;

View File

@@ -1,4 +1,4 @@
package com.massivecraft.factions.util;
package com.massivecraft.factions.util.adapters;
import com.google.gson.*;
import com.massivecraft.factions.FactionsPlugin;

View File

@@ -1,11 +0,0 @@
package com.massivecraft.factions.util.exceptions;
/**
* @author Saser
*/
public abstract class SaberException extends Exception {
public SaberException(String message) {
super(message);
}
}

View File

@@ -1,12 +0,0 @@
package com.massivecraft.factions.util.exceptions.impl;
import com.massivecraft.factions.util.exceptions.SaberException;
/**
* @author Saser
*/
public class DiscordException extends SaberException {
public DiscordException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,46 @@
package com.massivecraft.factions.util.wait;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.concurrent.ConcurrentHashMap;
/**
* Factions - Developed by Driftay.
* All rights reserved 2020.
* Creation Date: 4/4/2020
*/
public class WaitExecutor {
private static boolean enabled = false;
public static ConcurrentHashMap<Player, WaitTask> taskMap = new ConcurrentHashMap<>();
public static void startTask() {
if (enabled) return;
Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.instance, () ->
{
for (WaitTask task : taskMap.values()) {
int i = task.getWait() - 1;
if (i > 0) {
if (i != 1) {
task.getPlayer().sendMessage(task.getMessage().format((i + " Seconds")));
} else {
task.getPlayer().sendMessage(task.getMessage().format((i + " Second")));
}
task.setWait(i);
} else {
task.success();
taskMap.remove(task.getPlayer());
}
}
}, 0L, 20L);
enabled = true;
}
public static void handleAction(Player player) {
if (!taskMap.containsKey(player)) return;
taskMap.get(player).fail();
taskMap.remove(player);
}
}

View File

@@ -0,0 +1,47 @@
package com.massivecraft.factions.util.wait;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Player;
/**
* @author droppinganvil
*/
public class WaitTask {
private Integer wait;
private TL msg;
//Using player as to not have to convert every event
private Player player;
private WaitedTask origin;
public WaitTask(Integer wait, TL message, Player player, WaitedTask waitedTask) {
this.wait = wait;
this.msg = message;
this.player = player;
this.origin = waitedTask;
}
public Integer getWait() {
return wait;
}
public TL getMessage() {
return msg;
}
public Player getPlayer() {
return player;
}
public void setWait(Integer i) {
wait = i;
}
public void success() {
origin.handleSuccess(player);
}
public void fail() {
origin.handleFailure(player);
}
}

View File

@@ -0,0 +1,14 @@
package com.massivecraft.factions.util.wait;
import org.bukkit.entity.Player;
/**
* Factions - Developed by Driftay.
* All rights reserved 2020.
* Creation Date: 4/4/2020
*/
public interface WaitedTask {
void handleSuccess(Player player);
void handleFailure(Player player);
}