claim potion effects
This commit is contained in:
parent
c7a00e6b70
commit
9b1400b3d7
@ -1,13 +0,0 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ConfigPath {
|
||||
|
||||
@ExpectPlatform
|
||||
public static Path configPath() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class CrossPlatformStuff {
|
||||
|
||||
@ExpectPlatform
|
||||
public static Path configPath() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static StatusEffect effectFromString(String s) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static String stringFromEffect(StatusEffect s) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package io.github.flemmli97.flan.api;
|
||||
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
|
||||
public interface IPlayerData {
|
||||
|
||||
int getClaimBlocks();
|
||||
|
||||
int getAdditionalClaims();
|
||||
|
||||
int usedClaimBlocks();
|
||||
|
||||
default boolean canUseClaimBlocks(int amount) {
|
||||
if (ConfigHandler.config.maxClaimBlocks == -1)
|
||||
return true;
|
||||
int usedClaimsBlocks = this.usedClaimBlocks();
|
||||
return usedClaimsBlocks + amount <= this.getClaimBlocks() + this.getAdditionalClaims();
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
@ -13,6 +14,8 @@ import io.github.flemmli97.flan.config.Config;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@ -470,6 +473,27 @@ public class Claim implements IPermissionContainer {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addPotion(StatusEffect effect, int amplifier) {
|
||||
this.potions.put(effect, amplifier);
|
||||
this.setDirty(true);
|
||||
}
|
||||
|
||||
public void removePotion(StatusEffect effect) {
|
||||
this.potions.remove(effect);
|
||||
this.setDirty(true);
|
||||
}
|
||||
|
||||
public Map<StatusEffect, Integer> getPotions() {
|
||||
return this.potions;
|
||||
}
|
||||
|
||||
public void applyEffects(PlayerEntity player) {
|
||||
this.potions.forEach((effect, amp) -> {
|
||||
if (!player.hasStatusEffect(effect))
|
||||
player.applyStatusEffect(new StatusEffectInstance(effect, 200, amp-1, true, false));
|
||||
});
|
||||
}
|
||||
|
||||
public BlockPos getHomePos() {
|
||||
return this.homePos;
|
||||
}
|
||||
@ -504,6 +528,8 @@ public class Claim implements IPermissionContainer {
|
||||
else {
|
||||
this.homePos = new BlockPos(home.get(0).getAsInt(), home.get(1).getAsInt(), home.get(2).getAsInt());
|
||||
}
|
||||
JsonObject potion = ConfigHandler.fromJson(obj, "Potions");
|
||||
potion.entrySet().forEach(e -> this.potions.put(CrossPlatformStuff.effectFromString(e.getKey()), e.getValue().getAsInt()));
|
||||
if (ConfigHandler.fromJson(obj, "AdminClaim", false))
|
||||
this.owner = null;
|
||||
else
|
||||
@ -568,6 +594,9 @@ public class Claim implements IPermissionContainer {
|
||||
home.add(this.homePos.getY());
|
||||
home.add(this.homePos.getZ());
|
||||
obj.add("Home", home);
|
||||
JsonObject potions = new JsonObject();
|
||||
this.potions.forEach((effect, amp) -> potions.addProperty(CrossPlatformStuff.stringFromEffect(effect), amp));
|
||||
obj.add("Potions", potions);
|
||||
if (this.parent != null)
|
||||
obj.addProperty("Parent", this.parent.toString());
|
||||
if (!this.globalPerm.isEmpty()) {
|
||||
|
@ -165,7 +165,7 @@ public class CommandClaim {
|
||||
enoughBlocks = newData.canUseClaimBlocks(claim.getPlane());
|
||||
} else {
|
||||
OfflinePlayerData newData = new OfflinePlayerData(server, prof.getId());
|
||||
enoughBlocks = ConfigHandler.config.maxClaimBlocks == -1 || newData.getUsedClaimBlocks(server) + claim.getPlane() < newData.claimBlocks + newData.additionalClaimBlocks;
|
||||
enoughBlocks = ConfigHandler.config.maxClaimBlocks == -1 || newData.getUsedClaimBlocks() + claim.getPlane() < newData.claimBlocks + newData.additionalClaimBlocks;
|
||||
}
|
||||
}
|
||||
if (!enoughBlocks) {
|
||||
@ -418,7 +418,7 @@ public class CommandClaim {
|
||||
} else {
|
||||
OfflinePlayerData data = new OfflinePlayerData(server, of);
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
data.claimBlocks, data.additionalClaimBlocks, data.getUsedClaimBlocks(server)), Formatting.GOLD), false);
|
||||
data.claimBlocks, data.additionalClaimBlocks, data.getUsedClaimBlocks()), Formatting.GOLD), false);
|
||||
}
|
||||
}
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.listClaims, Formatting.GOLD), false);
|
||||
|
@ -3,7 +3,7 @@ package io.github.flemmli97.flan.config;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.github.flemmli97.flan.ConfigPath;
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
@ -85,7 +85,7 @@ public class Config {
|
||||
})));
|
||||
|
||||
public Config(MinecraftServer server) {
|
||||
File configDir = ConfigPath.configPath().resolve("flan").toFile();
|
||||
File configDir = CrossPlatformStuff.configPath().resolve("flan").toFile();
|
||||
try {
|
||||
if (!configDir.exists())
|
||||
configDir.mkdirs();
|
||||
|
@ -4,7 +4,7 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import io.github.flemmli97.flan.ConfigPath;
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@ -141,7 +141,7 @@ public class LangConfig {
|
||||
public LangCommands cmdLang = new LangCommands();
|
||||
|
||||
public LangConfig(MinecraftServer server) {
|
||||
File configDir = ConfigPath.configPath().resolve("flan").toFile();
|
||||
File configDir = CrossPlatformStuff.configPath().resolve("flan").toFile();
|
||||
//server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||
try {
|
||||
if (!configDir.exists())
|
||||
|
@ -326,6 +326,7 @@ public class EntityInteractEvents {
|
||||
if (player.getHungerManager().getSaturationLevel() < 2 && currentClaim.canInteract(player, PermissionRegistry.NOHUNGER, bPos, false)) {
|
||||
((IHungerAccessor) player.getHungerManager()).setSaturation(2);
|
||||
}
|
||||
currentClaim.applyEffects(player);
|
||||
}
|
||||
}
|
||||
} else if (player.age % 3 == 0) {
|
||||
|
@ -61,6 +61,11 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
group.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGroup, Formatting.GOLD));
|
||||
inv.setStack(i, group);
|
||||
break;
|
||||
case 4:
|
||||
ItemStack potions = new ItemStack(Items.POTION);
|
||||
potions.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGroup, Formatting.GOLD));
|
||||
inv.setStack(i, potions);
|
||||
break;
|
||||
case 8:
|
||||
ItemStack delete = new ItemStack(Items.BARRIER);
|
||||
delete.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuDelete, Formatting.RED));
|
||||
@ -74,7 +79,7 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
|
||||
@Override
|
||||
protected boolean isRightSlot(int slot) {
|
||||
return slot == 0 || slot == 2 || slot == 3 || slot == 8;
|
||||
return slot == 0 || slot == 2 || slot == 3 || slot == 4 || slot == 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -94,6 +99,11 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
player.getServer().execute(() -> GroupScreenHandler.openGroupMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
break;
|
||||
case 4:
|
||||
player.closeHandledScreen();
|
||||
player.getServer().execute(() -> PotionEditScreenHandler.openPotionMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
break;
|
||||
case 8:
|
||||
player.closeHandledScreen();
|
||||
player.getServer().execute(() -> ConfirmScreenHandler.openConfirmScreen(player, (bool) -> {
|
||||
|
@ -0,0 +1,136 @@
|
||||
package io.github.flemmli97.flan.gui;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PotionEditScreenHandler extends ServerOnlyScreenHandler {
|
||||
|
||||
private final Claim claim;
|
||||
|
||||
private boolean removeMode;
|
||||
|
||||
protected PotionEditScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim) {
|
||||
super(syncId, playerInventory, 6, claim);
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
public static void openPotionMenu(PlayerEntity player, Claim claim) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
return new PotionEditScreenHandler(syncId, inv, claim);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
return PermHelper.simpleColoredText("Claim Potions");
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
if (additionalData == null)
|
||||
return;
|
||||
Claim claim = (Claim) additionalData[0];
|
||||
Map<StatusEffect, Integer> potions = claim.getPotions();
|
||||
List<StatusEffect> key = Lists.newArrayList(potions.keySet());
|
||||
key.sort(Comparator.comparing(CrossPlatformStuff::stringFromEffect));
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText("Back", Formatting.DARK_RED));
|
||||
inv.setStack(i, close);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText("Add", Formatting.DARK_GREEN));
|
||||
inv.setStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText("Remove Mode: " + this.removeMode, Formatting.DARK_RED));
|
||||
inv.setStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1;
|
||||
if (id < potions.size()) {
|
||||
StatusEffect effect = key.get(id);
|
||||
ItemStack group = new ItemStack(Items.POTION);
|
||||
TranslatableText txt = new TranslatableText(effect.getTranslationKey());
|
||||
group.getOrCreateTag().putString("FlanEffect", CrossPlatformStuff.stringFromEffect(effect));
|
||||
group.setCustomName(txt.setStyle(txt.getStyle().withFormatting(Formatting.DARK_BLUE)).append(ServerScreenHelper.coloredGuiText("-" + potions.get(effect), Formatting.DARK_BLUE)));
|
||||
inv.setStack(i, group);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRightSlot(int slot) {
|
||||
return slot == 0 || slot == 3 || slot == 4 || (slot < 45 && slot > 8 && slot % 9 != 0 && slot % 9 != 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
player.closeHandledScreen();
|
||||
player.getServer().execute(() -> ClaimMenuScreenHandler.openClaimMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
if (index == 3) {
|
||||
player.closeHandledScreen();
|
||||
player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> {
|
||||
String[] potion = s.split(";");
|
||||
this.claim.addPotion(CrossPlatformStuff.effectFromString(potion[0]), Integer.parseInt(potion[1]));
|
||||
player.closeHandledScreen();
|
||||
player.getServer().execute(() -> PotionEditScreenHandler.openPotionMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_USE, 1, 1f);
|
||||
}, () -> {
|
||||
player.closeHandledScreen();
|
||||
player.getServer().execute(() -> PotionEditScreenHandler.openPotionMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
}));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
if (index == 4) {
|
||||
this.removeMode = !this.removeMode;
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText("Remove Mode: " + this.removeMode, Formatting.DARK_RED));
|
||||
slot.setStack(stack);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
ItemStack stack = slot.getStack();
|
||||
if (!stack.isEmpty() && this.removeMode) {
|
||||
String effect = stack.getOrCreateTag().getString("FlanEffect");
|
||||
this.claim.removePotion(CrossPlatformStuff.effectFromString(effect));
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_BAT_DEATH, 1, 1f);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ public class OfflinePlayerData {
|
||||
|
||||
public final int claimBlocks, additionalClaimBlocks;
|
||||
public final UUID owner;
|
||||
public final MinecraftServer server;
|
||||
|
||||
public OfflinePlayerData(MinecraftServer server, UUID uuid) {
|
||||
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
||||
@ -40,11 +41,12 @@ public class OfflinePlayerData {
|
||||
}
|
||||
this.claimBlocks = claim;
|
||||
this.additionalClaimBlocks = add;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public int getUsedClaimBlocks(MinecraftServer server) {
|
||||
public int getUsedClaimBlocks() {
|
||||
int usedClaimsBlocks = 0;
|
||||
for (ServerWorld world : server.getWorlds()) {
|
||||
for (ServerWorld world : this.server.getWorlds()) {
|
||||
Collection<Claim> claims = ClaimStorage.get(world).allClaimsFromPlayer(this.owner);
|
||||
if (claims != null)
|
||||
usedClaimsBlocks += claims.stream().filter(claim -> !claim.isAdminClaim()).mapToInt(Claim::getPlane).sum();
|
||||
|
@ -1,12 +0,0 @@
|
||||
package io.github.flemmli97.flan.fabric;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ConfigPathImpl {
|
||||
|
||||
public static Path configPath() {
|
||||
return FabricLoader.getInstance().getConfigDir();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package io.github.flemmli97.flan.fabric;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class CrossPlatformStuffImpl {
|
||||
|
||||
public static Path configPath() {
|
||||
return FabricLoader.getInstance().getConfigDir();
|
||||
}
|
||||
|
||||
public static StatusEffect effectFromString(String s) {
|
||||
return Registry.STATUS_EFFECT.get(new Identifier(s));
|
||||
}
|
||||
|
||||
public static String stringFromEffect(StatusEffect s) {
|
||||
return Registry.STATUS_EFFECT.getId(s).toString();
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package io.github.flemmli97.flan.forge;
|
||||
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ConfigPathImpl {
|
||||
|
||||
public static Path configPath() {
|
||||
return FMLPaths.CONFIGDIR.get();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.github.flemmli97.flan.forge;
|
||||
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class CrossPlatformStuffImpl {
|
||||
|
||||
public static Path configPath() {
|
||||
return FMLPaths.CONFIGDIR.get();
|
||||
}
|
||||
|
||||
public static StatusEffect effectFromString(String s) {
|
||||
return ForgeRegistries.POTIONS.getValue(new Identifier(s));
|
||||
}
|
||||
|
||||
public static String stringFromEffect(StatusEffect s) {
|
||||
return s.getRegistryName().toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user