F Reserve System ReAdded
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user