parent
4a1e884728
commit
828a406702
@ -14,6 +14,9 @@ Flan 1.7.0
|
|||||||
- defaultEnterMessage and defaultLeaveMessage:
|
- defaultEnterMessage and defaultLeaveMessage:
|
||||||
Automatically sets the enter/leave message to this
|
Automatically sets the enter/leave message to this
|
||||||
The claims name is passed on to this so "Entering %s" -> "Entering <Claim>"
|
The claims name is passed on to this so "Entering %s" -> "Entering <Claim>"
|
||||||
|
- Rewritten buy/sell system.
|
||||||
|
Its now possible to specify money, items or xp points as a "currency" value
|
||||||
|
For more info see the https://github.com/Flemmli97/Flan/wiki/Config#buysell-handler
|
||||||
|
|
||||||
Flan 1.6.9
|
Flan 1.6.9
|
||||||
======================
|
======================
|
||||||
|
@ -18,7 +18,6 @@ import io.github.flemmli97.flan.claim.PermHelper;
|
|||||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||||
import io.github.flemmli97.flan.gui.ClaimMenuScreenHandler;
|
import io.github.flemmli97.flan.gui.ClaimMenuScreenHandler;
|
||||||
import io.github.flemmli97.flan.gui.PersonalGroupScreenHandler;
|
import io.github.flemmli97.flan.gui.PersonalGroupScreenHandler;
|
||||||
import io.github.flemmli97.flan.integration.currency.CommandCurrency;
|
|
||||||
import io.github.flemmli97.flan.integration.permissions.PermissionNodeHandler;
|
import io.github.flemmli97.flan.integration.permissions.PermissionNodeHandler;
|
||||||
import io.github.flemmli97.flan.player.EnumDisplayType;
|
import io.github.flemmli97.flan.player.EnumDisplayType;
|
||||||
import io.github.flemmli97.flan.player.EnumEditMode;
|
import io.github.flemmli97.flan.player.EnumEditMode;
|
||||||
@ -84,9 +83,9 @@ public class CommandClaim {
|
|||||||
.then(Commands.literal("giveClaimBlocks").requires(src -> PermissionNodeHandler.perm(src, PermissionNodeHandler.cmdAdminGive, true)).then(Commands.argument("players", GameProfileArgument.gameProfile())
|
.then(Commands.literal("giveClaimBlocks").requires(src -> PermissionNodeHandler.perm(src, PermissionNodeHandler.cmdAdminGive, true)).then(Commands.argument("players", GameProfileArgument.gameProfile())
|
||||||
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks))))
|
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks))))
|
||||||
.then(Commands.literal("buyBlocks").requires(src -> PermissionNodeHandler.perm(src, PermissionNodeHandler.cmdBuy, false))
|
.then(Commands.literal("buyBlocks").requires(src -> PermissionNodeHandler.perm(src, PermissionNodeHandler.cmdBuy, false))
|
||||||
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandCurrency::buyClaimBlocks)))
|
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::buyClaimBlocks)))
|
||||||
.then(Commands.literal("sellBlocks").requires(src -> PermissionNodeHandler.perm(src, PermissionNodeHandler.cmdSell, false))
|
.then(Commands.literal("sellBlocks").requires(src -> PermissionNodeHandler.perm(src, PermissionNodeHandler.cmdSell, false))
|
||||||
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandCurrency::sellClaimBlocks)))
|
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::sellClaimBlocks)))
|
||||||
.then(Commands.literal("claimMessage").then(Commands.argument("type", StringArgumentType.word()).suggests((ctx, b) -> SharedSuggestionProvider.suggest(new String[]{"enter", "leave"}, b))
|
.then(Commands.literal("claimMessage").then(Commands.argument("type", StringArgumentType.word()).suggests((ctx, b) -> SharedSuggestionProvider.suggest(new String[]{"enter", "leave"}, b))
|
||||||
.then(Commands.argument("title", StringArgumentType.word()).suggests((ctx, b) -> SharedSuggestionProvider.suggest(new String[]{"title", "subtitle"}, b))
|
.then(Commands.argument("title", StringArgumentType.word()).suggests((ctx, b) -> SharedSuggestionProvider.suggest(new String[]{"title", "subtitle"}, b))
|
||||||
.then(Commands.literal("text").then(Commands.argument("component", ComponentArgument.textComponent()).executes(ctx -> CommandClaim.editClaimMessages(ctx, ComponentArgument.getComponent(ctx, "component")))))
|
.then(Commands.literal("text").then(Commands.argument("component", ComponentArgument.textComponent()).executes(ctx -> CommandClaim.editClaimMessages(ctx, ComponentArgument.getComponent(ctx, "component")))))
|
||||||
@ -801,4 +800,14 @@ public class CommandClaim {
|
|||||||
context.getSource().sendSuccess(cmdFeed, false);
|
context.getSource().sendSuccess(cmdFeed, false);
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int sellClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
boolean b = ConfigHandler.config.buySellHandler.sell(context.getSource().getPlayerOrException(), Math.max(0, IntegerArgumentType.getInteger(context, "amount")), m -> context.getSource().sendSuccess(m, false));
|
||||||
|
return b ? Command.SINGLE_SUCCESS : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int buyClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
boolean b = ConfigHandler.config.buySellHandler.buy(context.getSource().getPlayerOrException(), Math.max(0, IntegerArgumentType.getInteger(context, "amount")), m -> context.getSource().sendSuccess(m, false));
|
||||||
|
return b ? Command.SINGLE_SUCCESS : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,215 @@
|
|||||||
|
package io.github.flemmli97.flan.config;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import io.github.flemmli97.flan.claim.PermHelper;
|
||||||
|
import io.github.flemmli97.flan.integration.currency.CommandCurrency;
|
||||||
|
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class BuySellHandler {
|
||||||
|
|
||||||
|
private static int[] xpCalc;
|
||||||
|
|
||||||
|
private Type buyType = Type.MONEY;
|
||||||
|
private Type sellType = Type.MONEY;
|
||||||
|
|
||||||
|
private float buyAmount = -1;
|
||||||
|
private float sellAmount = -1;
|
||||||
|
|
||||||
|
private Ingredient ingredient = Ingredient.EMPTY;
|
||||||
|
|
||||||
|
public boolean buy(ServerPlayer player, int blocks, Consumer<Component> message) {
|
||||||
|
if (this.buyAmount == -1) {
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyDisabled"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (this.buyType) {
|
||||||
|
case MONEY -> {
|
||||||
|
return CommandCurrency.buyClaimBlocks(player, blocks, this.buyAmount, message);
|
||||||
|
}
|
||||||
|
case ITEM -> {
|
||||||
|
int deduct = Mth.ceil(blocks * this.buyAmount);
|
||||||
|
List<ItemStack> matching = new ArrayList<>();
|
||||||
|
int i = 0;
|
||||||
|
for (ItemStack stack : player.getInventory().items) {
|
||||||
|
if (this.ingredient.test(stack)) {
|
||||||
|
if (stack.isDamageableItem()) {
|
||||||
|
if (stack.getDamageValue() != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Ignore "special" items
|
||||||
|
if (!this.isJustRenamedItem(stack)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
matching.add(stack);
|
||||||
|
i += stack.getCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i < deduct) {
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyFailItem"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
i = deduct;
|
||||||
|
for (ItemStack stack : matching) {
|
||||||
|
if (i > stack.getCount()) {
|
||||||
|
int count = stack.getCount();
|
||||||
|
stack.setCount(0);
|
||||||
|
i -= count;
|
||||||
|
} else {
|
||||||
|
stack.shrink(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
|
data.setAdditionalClaims(data.getAdditionalClaims() + blocks);
|
||||||
|
message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("buySuccessItem"), blocks, deduct)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case XP -> {
|
||||||
|
int deduct = Mth.ceil(blocks * this.buyAmount);
|
||||||
|
if (deduct < totalXpPointsForLevel(player.experienceLevel) + player.experienceProgress * xpForLevel(player.experienceLevel + 1)) {
|
||||||
|
player.giveExperiencePoints(-deduct);
|
||||||
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
|
data.setAdditionalClaims(data.getAdditionalClaims() + blocks);
|
||||||
|
message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("buySuccessXP"), blocks, deduct)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyFailXP"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean sell(ServerPlayer player, int blocks, Consumer<Component> message) {
|
||||||
|
if (this.sellAmount == -1) {
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellDisabled"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
|
if (data.getAdditionalClaims() - Math.max(0, data.usedClaimBlocks() - data.getClaimBlocks()) < blocks) {
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellFail"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (this.sellType) {
|
||||||
|
case MONEY -> {
|
||||||
|
return CommandCurrency.sellClaimBlocks(player, blocks, this.sellAmount, message);
|
||||||
|
}
|
||||||
|
case ITEM -> {
|
||||||
|
if (this.ingredient.getItems().length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ItemStack stack = this.ingredient.getItems()[0];
|
||||||
|
int amount = Mth.floor(blocks * this.sellAmount);
|
||||||
|
while (amount > 0) {
|
||||||
|
ItemStack toGive = stack.copy();
|
||||||
|
if (amount > 64) {
|
||||||
|
toGive.setCount(64);
|
||||||
|
amount -= 64;
|
||||||
|
} else {
|
||||||
|
toGive.setCount(amount);
|
||||||
|
amount = 0;
|
||||||
|
}
|
||||||
|
boolean bl = player.getInventory().add(toGive);
|
||||||
|
if (!bl || !toGive.isEmpty()) {
|
||||||
|
ItemEntity itemEntity = player.drop(toGive, false);
|
||||||
|
if (itemEntity != null) {
|
||||||
|
itemEntity.setNoPickUpDelay();
|
||||||
|
itemEntity.setOwner(player.getUUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.setAdditionalClaims(data.getAdditionalClaims() - blocks);
|
||||||
|
message.accept(new TranslatableComponent(ConfigHandler.langManager.get("sellSuccessItem"), blocks, amount, new TranslatableComponent(stack.getDescriptionId()).withStyle(ChatFormatting.AQUA)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case XP -> {
|
||||||
|
int amount = Mth.floor(blocks * this.buyAmount);
|
||||||
|
player.giveExperiencePoints(amount);
|
||||||
|
data.setAdditionalClaims(data.getAdditionalClaims() - blocks);
|
||||||
|
message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("sellSuccessXP"), blocks, amount)));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isJustRenamedItem(ItemStack stack) {
|
||||||
|
if (!stack.hasTag())
|
||||||
|
return true;
|
||||||
|
if (stack.getTag().getAllKeys()
|
||||||
|
.stream().allMatch(s -> s.equals("Damage") || s.equals("RepairCost") || s.equals("display"))) {
|
||||||
|
CompoundTag tag = stack.getTag().getCompound("display");
|
||||||
|
return tag.contains("Name") && tag.size() == 1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int totalXpPointsForLevel(int level) {
|
||||||
|
if (xpCalc == null || level > xpCalc.length) {
|
||||||
|
xpCalc = new int[level + 50];
|
||||||
|
xpCalc[0] = 0;
|
||||||
|
for (int i = 1; i < xpCalc.length; i++) {
|
||||||
|
xpCalc[i] = xpForLevel(i) + xpCalc[i - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return xpCalc[level];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See {@link Player#getXpNeededForNextLevel()}
|
||||||
|
*/
|
||||||
|
private static int xpForLevel(int level) {
|
||||||
|
level -= 1;
|
||||||
|
if (level >= 30) {
|
||||||
|
return 112 + (level - 30) * 9;
|
||||||
|
}
|
||||||
|
if (level >= 15) {
|
||||||
|
return 37 + (level - 15) * 5;
|
||||||
|
}
|
||||||
|
return 7 + level * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObject toJson() {
|
||||||
|
JsonObject obj = new JsonObject();
|
||||||
|
obj.addProperty("buyType", this.buyType.toString());
|
||||||
|
obj.addProperty("sellType", this.sellType.toString());
|
||||||
|
obj.addProperty("buyValue", this.buyAmount);
|
||||||
|
obj.addProperty("sellValue", this.sellAmount);
|
||||||
|
obj.add("ingredient", this.ingredient.toJson());
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fromJson(JsonObject object) {
|
||||||
|
this.buyType = Type.valueOf(ConfigHandler.fromJson(object, "buyType", this.buyType.toString()));
|
||||||
|
this.sellType = Type.valueOf(ConfigHandler.fromJson(object, "sellType", this.sellType.toString()));
|
||||||
|
this.buyAmount = object.has("buyValue") ? object.get("buyValue").getAsFloat() : this.buyAmount;
|
||||||
|
this.sellAmount = object.has("sellValue") ? object.get("sellValue").getAsFloat() : this.sellAmount;
|
||||||
|
try {
|
||||||
|
this.ingredient = object.has("ingredient") ? Ingredient.fromJson(object.get("ingredient")) : Ingredient.EMPTY;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
this.ingredient = Ingredient.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
MONEY,
|
||||||
|
ITEM,
|
||||||
|
XP
|
||||||
|
}
|
||||||
|
}
|
@ -47,8 +47,7 @@ public class Config {
|
|||||||
public int claimDisplayTime = 1000;
|
public int claimDisplayTime = 1000;
|
||||||
public int permissionLevel = 2;
|
public int permissionLevel = 2;
|
||||||
|
|
||||||
public int sellPrice = -1;
|
public BuySellHandler buySellHandler = new BuySellHandler();
|
||||||
public int buyPrice = -1;
|
|
||||||
|
|
||||||
public boolean lenientBlockEntityCheck;
|
public boolean lenientBlockEntityCheck;
|
||||||
public List<String> breakBlockBlacklist = Lists.newArrayList(
|
public List<String> breakBlockBlacklist = Lists.newArrayList(
|
||||||
@ -167,8 +166,7 @@ public class Config {
|
|||||||
this.claimDisplayTime = ConfigHandler.fromJson(obj, "claimDisplayTime", this.claimDisplayTime);
|
this.claimDisplayTime = ConfigHandler.fromJson(obj, "claimDisplayTime", this.claimDisplayTime);
|
||||||
this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel);
|
this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel);
|
||||||
|
|
||||||
this.sellPrice = ConfigHandler.fromJson(obj, "sellPrice", this.sellPrice);
|
this.buySellHandler.fromJson(ConfigHandler.fromJson(obj, "buySellHandler"));
|
||||||
this.buyPrice = ConfigHandler.fromJson(obj, "buyPrice", this.buyPrice);
|
|
||||||
|
|
||||||
this.lenientBlockEntityCheck = ConfigHandler.fromJson(obj, "lenientBlockEntityCheck", this.lenientBlockEntityCheck);
|
this.lenientBlockEntityCheck = ConfigHandler.fromJson(obj, "lenientBlockEntityCheck", this.lenientBlockEntityCheck);
|
||||||
this.breakBlockBlacklist.clear();
|
this.breakBlockBlacklist.clear();
|
||||||
@ -262,8 +260,7 @@ public class Config {
|
|||||||
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
||||||
obj.addProperty("permissionLevel", this.permissionLevel);
|
obj.addProperty("permissionLevel", this.permissionLevel);
|
||||||
|
|
||||||
obj.addProperty("sellPrice", this.sellPrice);
|
obj.add("buySellHandler", this.buySellHandler.toJson());
|
||||||
obj.addProperty("buyPrice", this.buyPrice);
|
|
||||||
|
|
||||||
obj.addProperty("lenientBlockEntityCheck", this.lenientBlockEntityCheck);
|
obj.addProperty("lenientBlockEntityCheck", this.lenientBlockEntityCheck);
|
||||||
JsonArray blocksBreak = new JsonArray();
|
JsonArray blocksBreak = new JsonArray();
|
||||||
|
@ -24,6 +24,7 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -152,8 +153,15 @@ public class LangManager {
|
|||||||
this.defaultTranslation.put("buyDisabled", "Claimblocks purchasing is disabled");
|
this.defaultTranslation.put("buyDisabled", "Claimblocks purchasing is disabled");
|
||||||
this.defaultTranslation.put("sellFail", "Not enough claimblocks to sell");
|
this.defaultTranslation.put("sellFail", "Not enough claimblocks to sell");
|
||||||
this.defaultTranslation.put("buyFail", "Not enough money");
|
this.defaultTranslation.put("buyFail", "Not enough money");
|
||||||
|
this.defaultTranslation.put("buyFailItem", "Not enough items");
|
||||||
|
this.defaultTranslation.put("buyFailXP", "Not enough experience points");
|
||||||
this.defaultTranslation.put("sellSuccess", "Sold %1$s claimblocks for %2$s");
|
this.defaultTranslation.put("sellSuccess", "Sold %1$s claimblocks for %2$s");
|
||||||
|
this.defaultTranslation.put("sellSuccessItem", "Sold %1$s claimblocks for %3$s x%2$s");
|
||||||
|
this.defaultTranslation.put("sellSuccessXP", "Sold %1$s claimblocks for %2$s experience points");
|
||||||
this.defaultTranslation.put("buySuccess", "Bought %1$s claimblocks for %2$s");
|
this.defaultTranslation.put("buySuccess", "Bought %1$s claimblocks for %2$s");
|
||||||
|
this.defaultTranslation.put("buySuccessItem", "Bought %1$s claimblocks with %2$s items");
|
||||||
|
this.defaultTranslation.put("buySuccessXP", "Bought %1$s claimblocks with %2$s experience points");
|
||||||
|
|
||||||
this.defaultTranslation.put("currencyMissing", "Missing a supported currency mod");
|
this.defaultTranslation.put("currencyMissing", "Missing a supported currency mod");
|
||||||
|
|
||||||
this.defaultTranslation.put("trappedRescue", "Rescuing. Don't move for 5 seconds");
|
this.defaultTranslation.put("trappedRescue", "Rescuing. Don't move for 5 seconds");
|
||||||
@ -214,8 +222,8 @@ public class LangManager {
|
|||||||
this.defaultTranslationArray.put("command.giveClaimBlocks", new String[]{"giveClaimBlocks <amount>", "Gives a player additional claim blocks."});
|
this.defaultTranslationArray.put("command.giveClaimBlocks", new String[]{"giveClaimBlocks <amount>", "Gives a player additional claim blocks."});
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<String, String> translation = new LinkedHashMap<>();
|
private final Map<String, String> translation = new HashMap<>();
|
||||||
private final Map<String, String[]> translationArr = new LinkedHashMap<>();
|
private final Map<String, String[]> translationArr = new HashMap<>();
|
||||||
|
|
||||||
private final Path confDir;
|
private final Path confDir;
|
||||||
|
|
||||||
@ -260,20 +268,25 @@ public class LangManager {
|
|||||||
FileReader reader = new FileReader(legacy);
|
FileReader reader = new FileReader(legacy);
|
||||||
JsonObject obj = GSON.fromJson(reader, JsonObject.class);
|
JsonObject obj = GSON.fromJson(reader, JsonObject.class);
|
||||||
reader.close();
|
reader.close();
|
||||||
translation = new LinkedHashMap<>();
|
Map<String, String> fromConf = new HashMap<>();
|
||||||
translationArr = new LinkedHashMap<>();
|
Map<String, String[]> fromConfArr = new HashMap<>();
|
||||||
obj.entrySet().forEach(e -> {
|
obj.entrySet().forEach(e -> {
|
||||||
if (e.getKey().equals("commands")) {
|
if (e.getKey().equals("commands")) {
|
||||||
JsonObject commands = e.getValue().getAsJsonObject();
|
JsonObject commands = e.getValue().getAsJsonObject();
|
||||||
commands.entrySet().forEach(c -> translationArr.put("command." + c.getKey(), GSON.fromJson(c.getValue(), String[].class)));
|
commands.entrySet().forEach(c -> fromConfArr.put("command." + c.getKey(), GSON.fromJson(c.getValue(), String[].class)));
|
||||||
} else if (legacyPermissionGetter(e.getKey())) {
|
} else if (legacyPermissionGetter(e.getKey())) {
|
||||||
if (e.getValue().isJsonArray())
|
if (e.getValue().isJsonArray())
|
||||||
translationArr.put(e.getKey(), GSON.fromJson(e.getValue(), String[].class));
|
fromConfArr.put(e.getKey(), GSON.fromJson(e.getValue(), String[].class));
|
||||||
else
|
else
|
||||||
translationArr.put(e.getKey(), new String[]{e.getValue().getAsString()});
|
fromConfArr.put(e.getKey(), new String[]{e.getValue().getAsString()});
|
||||||
} else
|
} else
|
||||||
translation.put(e.getKey(), e.getValue().getAsString());
|
fromConf.put(e.getKey(), e.getValue().getAsString());
|
||||||
});
|
});
|
||||||
|
//To preserve order
|
||||||
|
translation = new LinkedHashMap<>();
|
||||||
|
translationArr = new LinkedHashMap<>();
|
||||||
|
this.defaultTranslation.forEach((key, t)-> translation.put(key, fromConf.getOrDefault(key, t)));
|
||||||
|
this.defaultTranslationArray.forEach((key, t)-> translationArr.put(key, fromConfArr.getOrDefault(key, t)));
|
||||||
} else {
|
} else {
|
||||||
translation = this.defaultTranslation;
|
translation = this.defaultTranslation;
|
||||||
translationArr = this.defaultTranslationArray;
|
translationArr = this.defaultTranslationArray;
|
||||||
@ -311,9 +324,12 @@ public class LangManager {
|
|||||||
});
|
});
|
||||||
//en_us is basically used as a default modifiable file
|
//en_us is basically used as a default modifiable file
|
||||||
if (lang.equals("en_us")) {
|
if (lang.equals("en_us")) {
|
||||||
this.defaultTranslation.forEach(this.translation::putIfAbsent);
|
//To preserve order
|
||||||
this.defaultTranslationArray.forEach(this.translationArr::putIfAbsent);
|
Map<String, String> ordered = new LinkedHashMap<>();
|
||||||
saveTo(this.confDir.resolve("en_us.json").toFile(), this.translation, this.translationArr);
|
Map<String, String[]> orderedArr = new LinkedHashMap<>();
|
||||||
|
this.defaultTranslation.forEach((key, t)-> ordered.put(key, this.translation.getOrDefault(key, t)));
|
||||||
|
this.defaultTranslationArray.forEach((key, t)-> orderedArr.put(key, this.translationArr.getOrDefault(key, t)));
|
||||||
|
saveTo(this.confDir.resolve("en_us.json").toFile(), ordered, orderedArr);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (lang.equals("en_us"))
|
if (lang.equals("en_us"))
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
package io.github.flemmli97.flan.integration.currency;
|
package io.github.flemmli97.flan.integration.currency;
|
||||||
|
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CommandCurrency {
|
public class CommandCurrency {
|
||||||
|
|
||||||
@ExpectPlatform
|
@ExpectPlatform
|
||||||
public static int sellClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
public static boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExpectPlatform
|
@ExpectPlatform
|
||||||
public static int buyClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
public static boolean buyClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package io.github.flemmli97.flan.integration.currency.fabric;
|
package io.github.flemmli97.flan.integration.currency.fabric;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import io.github.flemmli97.flan.Flan;
|
import io.github.flemmli97.flan.Flan;
|
||||||
import io.github.flemmli97.flan.claim.PermHelper;
|
import io.github.flemmli97.flan.claim.PermHelper;
|
||||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||||
@ -11,57 +7,57 @@ import io.github.flemmli97.flan.player.PlayerClaimData;
|
|||||||
import io.github.gunpowder.entities.StoredBalance;
|
import io.github.gunpowder.entities.StoredBalance;
|
||||||
import io.github.gunpowder.modelhandlers.BalanceHandler;
|
import io.github.gunpowder.modelhandlers.BalanceHandler;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CommandCurrencyImpl {
|
public class CommandCurrencyImpl {
|
||||||
|
|
||||||
public static int sellClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
public static boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) {
|
||||||
if (!Flan.gunpowder) {
|
if (value == -1) {
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("currencyMissing"), ChatFormatting.DARK_RED), false);
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellDisabled"), ChatFormatting.DARK_RED));
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
if (ConfigHandler.config.sellPrice == -1) {
|
if (Flan.gunpowder) {
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellDisabled"), ChatFormatting.DARK_RED), false);
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
return 0;
|
if (data.getAdditionalClaims() - Math.max(0, data.usedClaimBlocks() - data.getClaimBlocks()) < blocks) {
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellFail"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
StoredBalance bal = BalanceHandler.INSTANCE.getUser(player.getUUID());
|
||||||
|
BigDecimal price = BigDecimal.valueOf(blocks * value);
|
||||||
|
bal.setBalance(bal.getBalance().add(price));
|
||||||
|
BalanceHandler.INSTANCE.updateUser(bal);
|
||||||
|
data.setAdditionalClaims(data.getAdditionalClaims() - blocks);
|
||||||
|
message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("sellSuccess"), blocks, price), ChatFormatting.GOLD));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount"));
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("currencyMissing"), ChatFormatting.DARK_RED));
|
||||||
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayerOrException());
|
return false;
|
||||||
if (data.getAdditionalClaims() - Math.max(0, data.usedClaimBlocks() - data.getClaimBlocks()) < amount) {
|
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellFail"), ChatFormatting.DARK_RED), false);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
StoredBalance bal = BalanceHandler.INSTANCE.getUser(context.getSource().getPlayerOrException().getUUID());
|
|
||||||
BigDecimal price = BigDecimal.valueOf(amount * ConfigHandler.config.sellPrice);
|
|
||||||
bal.setBalance(bal.getBalance().add(price));
|
|
||||||
BalanceHandler.INSTANCE.updateUser(bal);
|
|
||||||
data.setAdditionalClaims(data.getAdditionalClaims() - amount);
|
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("sellSuccess"), amount, price), ChatFormatting.GOLD), false);
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int buyClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
public static boolean buyClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) {
|
||||||
if (!Flan.gunpowder) {
|
if (value == -1) {
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("currencyMissing"), ChatFormatting.DARK_RED), false);
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyDisabled"), ChatFormatting.DARK_RED));
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
if (ConfigHandler.config.buyPrice == -1) {
|
if (Flan.gunpowder) {
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyDisabled"), ChatFormatting.DARK_RED), false);
|
StoredBalance bal = BalanceHandler.INSTANCE.getUser(player.getUUID());
|
||||||
return 0;
|
BigDecimal price = BigDecimal.valueOf(Math.max(0, blocks * value));
|
||||||
|
if (bal.getBalance().compareTo(price) >= 0) {
|
||||||
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
|
data.setAdditionalClaims(data.getAdditionalClaims() + blocks);
|
||||||
|
bal.setBalance(bal.getBalance().subtract(price));
|
||||||
|
BalanceHandler.INSTANCE.updateUser(bal);
|
||||||
|
message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("buySuccess"), blocks, price), ChatFormatting.GOLD));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyFail"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
StoredBalance bal = BalanceHandler.INSTANCE.getUser(context.getSource().getPlayerOrException().getUUID());
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("currencyMissing"), ChatFormatting.DARK_RED));
|
||||||
int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount"));
|
return false;
|
||||||
BigDecimal price = BigDecimal.valueOf(amount * ConfigHandler.config.buyPrice);
|
|
||||||
if (bal.getBalance().compareTo(price) >= 0) {
|
|
||||||
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayerOrException());
|
|
||||||
data.setAdditionalClaims(data.getAdditionalClaims() + amount);
|
|
||||||
bal.setBalance(bal.getBalance().subtract(price));
|
|
||||||
BalanceHandler.INSTANCE.updateUser(bal);
|
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("buySuccess"), amount, price), ChatFormatting.GOLD), false);
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyFail"), ChatFormatting.DARK_RED), false);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package io.github.flemmli97.flan.integration.currency.forge;
|
package io.github.flemmli97.flan.integration.currency.forge;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import dicemc.money.MoneyMod;
|
import dicemc.money.MoneyMod;
|
||||||
import dicemc.money.storage.MoneyWSD;
|
import dicemc.money.storage.MoneyWSD;
|
||||||
import io.github.flemmli97.flan.Flan;
|
import io.github.flemmli97.flan.Flan;
|
||||||
@ -11,56 +7,56 @@ import io.github.flemmli97.flan.claim.PermHelper;
|
|||||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CommandCurrencyImpl {
|
public class CommandCurrencyImpl {
|
||||||
|
|
||||||
public static int sellClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
public static boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) {
|
||||||
if (!Flan.diceMCMoneySign) {
|
if (value == -1) {
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("currencyMissing"), ChatFormatting.DARK_RED), false);
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellDisabled"), ChatFormatting.DARK_RED));
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
if (ConfigHandler.config.sellPrice == -1) {
|
if (Flan.diceMCMoneySign) {
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellDisabled"), ChatFormatting.DARK_RED), false);
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
return 0;
|
if (data.getAdditionalClaims() - Math.max(0, data.usedClaimBlocks() - data.getClaimBlocks()) < blocks) {
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellFail"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
double price = blocks * value;
|
||||||
|
MoneyWSD.get(player.getLevel()).changeBalance(MoneyMod.AcctTypes.PLAYER.key, player.getUUID(), price);
|
||||||
|
data.setAdditionalClaims(data.getAdditionalClaims() - blocks);
|
||||||
|
message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("sellSuccess"), blocks, price), ChatFormatting.GOLD));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount"));
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("currencyMissing"), ChatFormatting.DARK_RED));
|
||||||
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayerOrException());
|
return false;
|
||||||
if (data.getAdditionalClaims() - Math.max(0, data.usedClaimBlocks() - data.getClaimBlocks()) < amount) {
|
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("sellFail"), ChatFormatting.DARK_RED), false);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
double price = amount * ConfigHandler.config.sellPrice;
|
|
||||||
MoneyWSD.get(context.getSource().getLevel()).changeBalance(MoneyMod.AcctTypes.PLAYER.key, context.getSource().getPlayerOrException().getUUID(), price);
|
|
||||||
data.setAdditionalClaims(data.getAdditionalClaims() - amount);
|
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("sellSuccess"), amount, price), ChatFormatting.GOLD), false);
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int buyClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
public static boolean buyClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) {
|
||||||
if (!Flan.diceMCMoneySign) {
|
if (value == -1) {
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("currencyMissing"), ChatFormatting.DARK_RED), false);
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyDisabled"), ChatFormatting.DARK_RED));
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
if (ConfigHandler.config.buyPrice == -1) {
|
if (Flan.diceMCMoneySign) {
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyDisabled"), ChatFormatting.DARK_RED), false);
|
UUID uuid = player.getUUID();
|
||||||
return 0;
|
MoneyWSD manager = MoneyWSD.get(player.getLevel());
|
||||||
|
double bal = manager.getBalance(MoneyMod.AcctTypes.PLAYER.key, uuid);
|
||||||
|
double price = blocks * value;
|
||||||
|
if (bal >= price) {
|
||||||
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
|
data.setAdditionalClaims(data.getAdditionalClaims() + blocks);
|
||||||
|
manager.changeBalance(MoneyMod.AcctTypes.PLAYER.key, uuid, -price);
|
||||||
|
message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("buySuccess"), blocks, price), ChatFormatting.GOLD));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyFail"), ChatFormatting.DARK_RED));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
UUID uuid = context.getSource().getPlayerOrException().getUUID();
|
message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("currencyMissing"), ChatFormatting.DARK_RED));
|
||||||
MoneyWSD manager = MoneyWSD.get(context.getSource().getLevel());
|
return false;
|
||||||
double bal = manager.getBalance(MoneyMod.AcctTypes.PLAYER.key, uuid);
|
|
||||||
int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount"));
|
|
||||||
double price = amount * ConfigHandler.config.buyPrice;
|
|
||||||
if (bal >= price) {
|
|
||||||
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayerOrException());
|
|
||||||
data.setAdditionalClaims(data.getAdditionalClaims() + amount);
|
|
||||||
manager.changeBalance(MoneyMod.AcctTypes.PLAYER.key, uuid, -price);
|
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("buySuccess"), amount, price), ChatFormatting.GOLD), false);
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyFail"), ChatFormatting.DARK_RED), false);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user