F Reserve System ReAdded

This commit is contained in:
Driftay 2019-12-31 02:56:45 -05:00
parent 05cfd5d8b0
commit 4c90bae87c
10 changed files with 153 additions and 1 deletions

@ -100,7 +100,8 @@ public class Conf {
public static boolean worldGuardChecking = false;
public static boolean worldGuardBuildPriority = false;
public static boolean factionsDrainEnabled = false;
//RESERVE
public static boolean useReserveSystem = true;
//AUDIT
public static boolean useAuditSystem = true;

@ -14,6 +14,8 @@ import com.massivecraft.factions.cmd.audit.FLogType;
import com.massivecraft.factions.cmd.check.CheckTask;
import com.massivecraft.factions.cmd.check.WeeWooTask;
import com.massivecraft.factions.cmd.chest.AntiChestListener;
import com.massivecraft.factions.cmd.reserve.ListParameterizedType;
import com.massivecraft.factions.cmd.reserve.ReserveObject;
import com.massivecraft.factions.discord.Discord;
import com.massivecraft.factions.discord.DiscordListener;
import com.massivecraft.factions.integration.Econ;
@ -54,6 +56,9 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import java.io.*;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
@ -94,6 +99,7 @@ public class FactionsPlugin extends MPlugin {
public List<String> itemList = getConfig().getStringList("fchest.Items-Not-Allowed");
private Worldguard wg;
private FLogManager fLogManager;
private List<ReserveObject> reserveObjects;
public FactionsPlugin() {
@ -300,6 +306,28 @@ public class FactionsPlugin extends MPlugin {
this.getCommand(refCommand).setExecutor(cmdBase);
if (!CommodoreProvider.isSupported()) this.getCommand(refCommand).setTabCompleter(this);
reserveObjects = new ArrayList<>();
String path = Paths.get(this.getDataFolder().getAbsolutePath()).toAbsolutePath().toString() + File.separator + "reserves.json";
File file = new File(path);
try {
String json;
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
json = String.join("", Files.readAllLines(Paths.get(file.getPath()))).replace("\n", "").replace("\r", "");
if (json.equalsIgnoreCase("")) {
Files.write(Paths.get(path), "[]".getBytes());
json = "[]";
}
reserveObjects = this.getGsonBuilder().create().fromJson(json, new ListParameterizedType(ReserveObject.class));
if (reserveObjects == null) {
reserveObjects = new ArrayList<>();
}
}
catch (Exception e) {
e.printStackTrace();
}
if (getDescription().getFullName().contains("BETA")) {
divider();
@ -689,6 +717,10 @@ public class FactionsPlugin extends MPlugin {
return Factions.getInstance().getFactionTags();
}
public List<ReserveObject> getFactionReserves() {
return this.reserveObjects;
}
// Get a list of all players in the specified faction
public Set<String> getPlayersInFaction(String factionTag) {
Set<String> players = new HashSet<>();

@ -17,6 +17,7 @@ import com.massivecraft.factions.cmd.relational.CmdRelationAlly;
import com.massivecraft.factions.cmd.relational.CmdRelationEnemy;
import com.massivecraft.factions.cmd.relational.CmdRelationNeutral;
import com.massivecraft.factions.cmd.relational.CmdRelationTruce;
import com.massivecraft.factions.cmd.reserve.CmdReserve;
import com.massivecraft.factions.cmd.roles.CmdDemote;
import com.massivecraft.factions.cmd.roles.CmdPromote;
import com.massivecraft.factions.cmd.tnt.CmdTnt;
@ -166,6 +167,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
public CmdDrain cmdDrain = new CmdDrain();
public CmdLookup cmdLookup = new CmdLookup();
public CmdAudit cmdAudit = new CmdAudit();
public CmdReserve cmdReserve = new CmdReserve();
//Variables to know if we already setup certain sub commands
public Boolean discordEnabled = false;
public Boolean checkEnabled = false;
@ -315,6 +317,11 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
this.addSubCommand(this.cmdDiscord);
discordEnabled = true;
}
//Reserve
if(Conf.useReserveSystem){
this.addSubCommand(this.cmdReserve);
}
//PayPal
if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled", false) && !fPayPalEnabled) {
this.addSubCommand(this.cmdPaypalSet);

@ -0,0 +1,39 @@
package com.massivecraft.factions.cmd.reserve;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
/**
* @author Saser
*/
public class CmdReserve extends FCommand {
public CmdReserve() {
this.aliases.add("reserve");
this.requiredArgs.add("tag");
this.requiredArgs.add("player");
this.requirements = new CommandRequirements.Builder(
Permission.RESERVE).build();
}
@Override
public void perform(CommandContext context) {
ReserveObject reserve = FactionsPlugin.getInstance().getFactionReserves().stream().filter(faction -> faction.getFactionName().equalsIgnoreCase(context.argAsString(0))).findFirst().orElse(null);
if (reserve != null) {
context.msg(TL.COMMAND_RESERVE_ALREADYRESERVED, context.argAsString(0));
return;
}
context.msg(TL.COMMAND_RESERVE_SUCCESS, context.argAsString(0), context.argAsString(1));
FactionsPlugin.getInstance().getFactionReserves().add(new ReserveObject(context.argAsString(1), context.argAsString(0)));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_RESERVE_DESCRIPTION;
}
}

@ -0,0 +1,23 @@
package com.massivecraft.factions.cmd.reserve;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
/**
* @author Saser
*/
public class ListParameterizedType implements ParameterizedType {
private Type type;
public ListParameterizedType(Type type) { this.type = type; }
@Override
public Type[] getActualTypeArguments() { return new Type[] { this.type }; }
@Override
public Type getRawType() { return ArrayList.class; }
@Override
public Type getOwnerType() { return null; }
}

@ -0,0 +1,24 @@
package com.massivecraft.factions.cmd.reserve;
import com.google.gson.*;
import java.lang.reflect.Type;
/**
* @author Saser
*/
public class ReserveAdapter implements JsonSerializer<ReserveObject>, JsonDeserializer<ReserveObject> {
public ReserveObject deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject object = jsonElement.getAsJsonObject();
ReserveObject faction = new ReserveObject(object.get("username").getAsString(), object.get("name").getAsString());
return faction;
}
public JsonElement serialize(ReserveObject data, final Type type, final JsonSerializationContext jsonSerializationContext) {
JsonObject object = new JsonObject();
object.add("username", new JsonPrimitive(data.getName()));
object.add("name", new JsonPrimitive(data.getFactionName()));
return object;
}
}

@ -0,0 +1,19 @@
package com.massivecraft.factions.cmd.reserve;
/**
* @author Saser
*/
public class ReserveObject {
private String name;
private String factionName;
public ReserveObject(String name, String factionName){
this.name = name;
this.factionName = factionName;
}
public String getName() {
return this.name;
}
public String getFactionName() {
return this.factionName;
}
}

@ -92,6 +92,7 @@ public enum Permission {
OPEN("open"),
OWNER("owner"),
OWNERLIST("ownerlist"),
RESERVE("reserve"),
SET_GUILD("setguild"),
SET_PEACEFUL("setpeaceful"),
SET_PERMANENT("setpermanent"),

@ -734,6 +734,11 @@ public enum TL {
COMMAND_RELOAD_TIME("&c&l[!]&7 Reloaded &call &7configuration files from disk, took &c%1$d ms."),
COMMAND_RELOAD_DESCRIPTION("Reload data file(s) from disk"),
COMMAND_RESERVE_DESCRIPTION("Reserve any faction name for any player"),
COMMAND_RESERVE_SUCCESS("&a&l[!] &7You have reserved the faction &a%1$s &7for player &a%2$s"),
COMMAND_RESERVE_ALREADYRESERVED("&c&l[!] &7The faction &b%1$s &7has already been reserved!"),
COMMAND_SAFEUNCLAIMALL_DESCRIPTION("Unclaim all safezone land"),
COMMAND_SAFEUNCLAIMALL_UNCLAIMED("&c&l[!]&7 You unclaimed&c ALL&7 safe zone land."),
COMMAND_SAFEUNCLAIMALL_UNCLAIMEDLOG("&c&l[!]&7 &c%1$s&7 unclaimed all safe zones."),

@ -13,6 +13,7 @@ permissions:
factions.kit.admin:
description: All faction permissions.
children:
factions.reserve: true
factions.kit.mod: true
factions.config: true
factions.convert: true