add gunpowder currency support. disabled by default

This commit is contained in:
Flemmli97 2021-05-31 14:30:18 +02:00
parent a4c8eb885d
commit 146a670f38
8 changed files with 107 additions and 0 deletions

View File

@ -1,3 +1,14 @@
Flan 1.3.3
======================
- Some blocks permission changed from PROJECTILES to OPENCONTAINER on direct interaction
Affected blocks: campfire, tnt, (chorus fruit), bells
Direct interaction as in right clicking the block. For actual projectile hits this remains unchanged
- Fix several entities not protected on indirect non projectile player attacks (e.g. through player ignited tnt)-
More noticable with other mods #52
- Add gunpowder currency support.
Enables the purchase and selling of claim blocks. Price configurable. Disabled by default
Only selling and purchase of additional claim blocks possible (not the ones you get with time).
Flan 1.3.2 Flan 1.3.2
====================== ======================
- Change gui item text to non italic (there are some very picky people) - Change gui item text to non italic (there are some very picky people)

View File

@ -12,10 +12,15 @@ group = project.maven_group
repositories { repositories {
mavenCentral() mavenCentral()
jcenter()
maven { maven {
name = 'Fabric-Permission-API' name = 'Fabric-Permission-API'
url 'https://oss.sonatype.org/content/repositories/snapshots' url 'https://oss.sonatype.org/content/repositories/snapshots'
} }
maven {
name = "Gunpowder"
url = "https://maven.martmists.com/releases"
}
} }
dependencies { dependencies {
@ -31,6 +36,7 @@ dependencies {
include group: 'org.yaml', name: 'snakeyaml', version: '1.25' include group: 'org.yaml', name: 'snakeyaml', version: '1.25'
modImplementation 'me.lucko:fabric-permissions-api:0.1-SNAPSHOT' modImplementation 'me.lucko:fabric-permissions-api:0.1-SNAPSHOT'
modCompileOnly "io.github.gunpowder:gunpowder-api:${gunpowder_version}+1.16.2"
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them. // You may need to force-disable transitiveness on them.
} }

View File

@ -25,6 +25,7 @@ public class Flan implements ModInitializer {
public static final Logger logger = LogManager.getLogger("flan"); public static final Logger logger = LogManager.getLogger("flan");
public static boolean permissionAPI; public static boolean permissionAPI;
public static boolean gunpowder;
@Override @Override
public void onInitialize() { public void onInitialize() {
@ -40,6 +41,7 @@ public class Flan implements ModInitializer {
CommandRegistrationCallback.EVENT.register(CommandClaim::register); CommandRegistrationCallback.EVENT.register(CommandClaim::register);
permissionAPI = FabricLoader.getInstance().isModLoaded("fabric-permissions-api-v0"); permissionAPI = FabricLoader.getInstance().isModLoaded("fabric-permissions-api-v0");
gunpowder = FabricLoader.getInstance().isModLoaded("gunpowder-currency");
} }
public void lockRegistry(MinecraftServer server) { public void lockRegistry(MinecraftServer server) {

View File

@ -71,6 +71,10 @@ public class CommandClaim {
.executes(CommandClaim::adminDeleteAll)))) .executes(CommandClaim::adminDeleteAll))))
.then(CommandManager.literal("giveClaimBlocks").requires(src -> CommandPermission.perm(src, CommandPermission.cmdAdminGive, true)).then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()) .then(CommandManager.literal("giveClaimBlocks").requires(src -> CommandPermission.perm(src, CommandPermission.cmdAdminGive, true)).then(CommandManager.argument("players", GameProfileArgumentType.gameProfile())
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks)))) .then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks))))
.then(CommandManager.literal("buyBlocks").requires(src -> CommandPermission.perm(src, CommandPermission.cmdBuy, false))
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandCurrency::buyClaimBlocks)))
.then(CommandManager.literal("sellBlocks").requires(src -> CommandPermission.perm(src, CommandPermission.cmdSell, false))
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandCurrency::sellClaimBlocks)))
.then(CommandManager.literal("group").requires(src -> CommandPermission.perm(src, CommandPermission.cmdGroup)) .then(CommandManager.literal("group").requires(src -> CommandPermission.perm(src, CommandPermission.cmdGroup))
.then(CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.string()).executes(CommandClaim::addGroup))) .then(CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.string()).executes(CommandClaim::addGroup)))
.then(CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.string()) .then(CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.string())

View File

@ -0,0 +1,66 @@
package com.flemmli97.flan.commands;
import com.flemmli97.flan.Flan;
import com.flemmli97.flan.claim.PermHelper;
import com.flemmli97.flan.config.ConfigHandler;
import com.flemmli97.flan.player.PlayerClaimData;
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.gunpowder.api.GunpowderMod;
import io.github.gunpowder.api.module.currency.dataholders.StoredBalance;
import io.github.gunpowder.api.module.currency.modelhandlers.BalanceHandler;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Formatting;
import java.math.BigDecimal;
public class CommandCurrency {
public static int sellClaimBlocks(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
if (!Flan.gunpowder) {
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.gunpowderMissing, Formatting.DARK_RED), false);
return 0;
}
if (ConfigHandler.config.sellPrice == -1) {
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.sellDisabled, Formatting.DARK_RED), false);
return 0;
}
int amount = IntegerArgumentType.getInteger(context, "amount");
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayer());
if (data.getAdditionalClaims() - data.usedClaimBlocks() + data.getClaimBlocks() < amount) {
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.sellFail, Formatting.DARK_RED), false);
return 0;
}
StoredBalance bal = GunpowderMod.getInstance().getRegistry().getModelHandler(BalanceHandler.class).getUser(context.getSource().getPlayer().getUuid());
BigDecimal price = BigDecimal.valueOf(amount * ConfigHandler.config.sellPrice);
bal.setBalance(bal.getBalance().add(price));
data.setAdditionalClaims(data.getAdditionalClaims() - amount);
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.sellSuccess, amount, price), Formatting.GOLD), false);
return Command.SINGLE_SUCCESS;
}
public static int buyClaimBlocks(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
if (!Flan.gunpowder) {
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.gunpowderMissing, Formatting.DARK_RED), false);
return 0;
}
if (ConfigHandler.config.buyPrice == -1) {
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.buyDisabled, Formatting.DARK_RED), false);
return 0;
}
StoredBalance bal = GunpowderMod.getInstance().getRegistry().getModelHandler(BalanceHandler.class).getUser(context.getSource().getPlayer().getUuid());
int amount = IntegerArgumentType.getInteger(context, "amount");
BigDecimal price = BigDecimal.valueOf(amount * ConfigHandler.config.buyPrice);
if (bal.getBalance().compareTo(price) > 0) {
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayer());
data.setAdditionalClaims(data.getAdditionalClaims() + amount);
bal.setBalance(bal.getBalance().subtract(price));
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.buySuccess, amount, price), Formatting.GOLD), false);
return Command.SINGLE_SUCCESS;
}
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.buyFail, Formatting.DARK_RED), false);
return 0;
}
}

View File

@ -36,6 +36,9 @@ public class CommandPermission {
public static final String cmdGroup = "flan.command.group"; public static final String cmdGroup = "flan.command.group";
public static final String cmdPermission = "flan.command.permission"; public static final String cmdPermission = "flan.command.permission";
public static final String cmdSell = "flan.command.buy";
public static final String cmdBuy = "flan.command.sell";
public static boolean perm(CommandSource src, String perm) { public static boolean perm(CommandSource src, String perm) {
return perm(src, perm, false); return perm(src, perm, false);
} }

View File

@ -46,6 +46,9 @@ public class Config {
public int claimDisplayTime = 1000; public int claimDisplayTime = 1000;
public int permissionLevel = 2; public int permissionLevel = 2;
public int sellPrice = -1;
public int buyPrice = -1;
public boolean log; public boolean log;
public Map<String, Map<ClaimPermission, Boolean>> defaultGroups = createHashMap(map -> { public Map<String, Map<ClaimPermission, Boolean>> defaultGroups = createHashMap(map -> {
@ -139,6 +142,8 @@ public class Config {
}); });
this.log = ConfigHandler.fromJson(obj, "enableLogs", this.log); this.log = ConfigHandler.fromJson(obj, "enableLogs", this.log);
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.buyPrice = ConfigHandler.fromJson(obj, "buyPrice", this.buyPrice);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -182,6 +187,8 @@ public class Config {
}); });
obj.add("globalDefaultPerms", global); obj.add("globalDefaultPerms", global);
obj.addProperty("enableLogs", this.log); obj.addProperty("enableLogs", this.log);
obj.addProperty("sellPrice", this.sellPrice);
obj.addProperty("buyPrice", this.buyPrice);
try { try {
FileWriter writer = new FileWriter(this.config); FileWriter writer = new FileWriter(this.config);
ConfigHandler.GSON.toJson(obj, writer); ConfigHandler.GSON.toJson(obj, writer);

View File

@ -108,6 +108,14 @@ public class LangConfig {
public String screenPersonalGroups = "Personal-Groups"; public String screenPersonalGroups = "Personal-Groups";
public String screenPersonalPermissions = "Personal Permissions for %s"; public String screenPersonalPermissions = "Personal Permissions for %s";
public String sellDisabled = "Claimblocks selling is disabled";
public String buyDisabled = "Claimblocks purchasing is disabled";
public String sellFail = "Not enough claimblocks to sell";
public String buyFail = "Not enough money";
public String sellSuccess = "Sold %1$s claimblocks for %2$s";
public String buySuccess = "Bought %1$s claimblocks for %2$s";
public String gunpowderMissing = "Missing gunpowder currency mod";
public LangConfig(MinecraftServer server) { public LangConfig(MinecraftServer server) {
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile(); File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
//server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile(); //server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();