Skip to content

Commit

Permalink
chore: Island protection
Browse files Browse the repository at this point in the history
Signed-off-by: Awakened-Redstone <[email protected]>
  • Loading branch information
Awakened-Redstone committed May 14, 2024
1 parent 6f86be2 commit bd89ca4
Show file tree
Hide file tree
Showing 127 changed files with 1,891 additions and 2,751 deletions.
32 changes: 23 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ plugins {
sourceSets {
main {
resources {
srcDirs += [
'src/main/generated'
]
srcDirs += ['src/main/generated']
}
}

testmod {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
}

loom {
Expand All @@ -26,6 +29,12 @@ loom {
ideConfigGenerated = true
runDir "build/datagen"
}

testmodServer {
server()
name = "Testmod Server"
source sourceSets.testmod
}
}
}

Expand All @@ -34,6 +43,7 @@ version = project.mod_version
group = project.maven_group

repositories {
mavenLocal()
maven { url "https://maven.nucleoid.xyz" }
maven { url "https://maven.awakenedredstone.com" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
Expand All @@ -50,9 +60,9 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api}"
//endregion
// region Cardinal Components
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-api:${project.cardinal_components_api}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_api}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-world:${project.cardinal_components_api}"
modImplementation "org.ladysnake.cardinal-components-api:cardinal-components-api:${project.cardinal_components_api}"
include "org.ladysnake.cardinal-components-api:cardinal-components-base:${project.cardinal_components_api}"
include "org.ladysnake.cardinal-components-api:cardinal-components-world:${project.cardinal_components_api}"
// endregion
// region Nucleoid
modImplementation include("xyz.nucleoid:fantasy:${project.fantasy}")
Expand All @@ -76,6 +86,10 @@ dependencies {
// region Non mod dependencies
include api("blue.endless:jankson:${project.jankson_version}")
//endregion

// region Tests
testmodImplementation sourceSets.main.output
//endregion
}

processResources {
Expand All @@ -88,12 +102,12 @@ processResources {
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
//noinspection GroovyAssignabilityCheck
it.options.release = 17
it.options.release = 21
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
withSourcesJar()
}

Expand Down
36 changes: 18 additions & 18 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs = -Xmx2G
org.gradle.jvmargs=-Xmx2G

# Mod Properties
maven_group = com.awakenedredstone
archives_base_name = neoskies
mod_version = 1.0.0-alpha.1
maven_group=com.awakenedredstone
archives_base_name=neoskies
mod_version=1.0.0-alpha.1

# Dependencies | Check these on https://fabricmc.net/develop
minecraft_version = 1.20.4
yarn_mappings = 1.20.4+build.3
fabric_loader = 0.15.7
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
fabric_loader=0.15.10

fabric_api = 0.96.11+1.20.4
fabric_api=0.98.0+1.20.6

cardinal_components_api = 5.4.0
cardinal_components_api=6.0.0-beta.3

server_gui = 1.4.2+1.20.4
placeholder_api = 2.3.0+1.20.3
common_protection_api = 1.0.0
common_economy_api = 1.1.1
polymer = 0.7.7+1.20.4
server_gui=1.5.0+1.20.5
placeholder_api=2.4.0-pre.1+1.20.5
common_protection_api=1.0.0
common_economy_api=1.1.1
polymer=0.8.0-beta.3+1.20.5-rc2

fantasy = 0.5.0+1.20.4
server_translations_api = 2.2.0+1.20.3-rc1
stimuli = 0.4.10+1.20.4
fantasy=0.6.0+1.20.6
server_translations_api=2.3.0+1.20.5-rc2
stimuli=0.4.10+1.20.6-local.1

fabric_permission_api = 0.2-SNAPSHOT
fabric_permission_api=0.2-SNAPSHOT

jankson_version=1.2.2
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.awakenedredstone.neoskies.gui.polymer.CBGuiElement;
import com.awakenedredstone.neoskies.gui.polymer.CBGuiElementBuilder;
import com.awakenedredstone.neoskies.util.MapBuilder;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import com.awakenedredstone.neoskies.logic.Island;
Expand All @@ -18,8 +18,8 @@
import java.util.*;

@Deprecated //TODO: Replace with just registry
public class SettingsManager {
private static final Map<Identifier, IslandSettings> defaultSettings = new HashMap<>();
public class IslandSettingsManager {
private static final SortedMap<Identifier, IslandSettings> defaultSettings = new TreeMap<>();
private static final Map<Identifier, CBGuiElement> icons = new HashMap<>();

public static boolean registerIcon(Identifier identifier, CBGuiElement icon) {
Expand Down Expand Up @@ -55,23 +55,17 @@ public static Map<Identifier, CBGuiElement> getIcons() {

public static CBGuiElement getIcon(Identifier identifier, Island island) {
CBGuiElementBuilder builder = icons.getOrDefault(identifier, new CBGuiElementBuilder(Items.PAPER).build()).getBuilder();
builder.hideFlag(ItemStack.TooltipSection.ADDITIONAL)
.hideFlag(ItemStack.TooltipSection.DYE)
.hideFlag(ItemStack.TooltipSection.CAN_DESTROY)
.hideFlag(ItemStack.TooltipSection.CAN_PLACE)
.hideFlag(ItemStack.TooltipSection.ENCHANTMENTS)
.hideFlag(ItemStack.TooltipSection.MODIFIERS)
.hideFlag(ItemStack.TooltipSection.UNBREAKABLE)
builder.hideDefaultTooltip()
.setLore(buildLore(island, identifier))
.setName(Texts.of(identifier.getNamespace() + ".island_settings." + identifier.getPath()))
.setName(Texts.of("island_settings." + identifier.toTranslationKey()))
.setCallback((index, type, action, gui) -> {
switch (type) {
case MOUSE_LEFT -> {
gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
offsetPermission(island.getSettings().get(identifier), 1);
}
case MOUSE_RIGHT -> {
gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
offsetPermission(island.getSettings().get(identifier), -1);
}
}
Expand All @@ -81,7 +75,7 @@ public static CBGuiElement getIcon(Identifier identifier, Island island) {

private static List<Text> buildLore(Island island, Identifier identifier) {
List<Text> lore = new ArrayList<>();
lore.add(Texts.of(identifier.getNamespace() + ".island_settings." + identifier.getPath() + ".description"));
lore.add(Text.empty().setStyle(Style.EMPTY.withItalic(false)).append(Texts.of("island_settings." + identifier.toTranslationKey() + ".description")));
lore.add(Text.empty());
int value = island.getSettings().get(identifier).permissionLevel.getLevel();
List<Integer> levels = new ArrayList<>();
Expand All @@ -93,16 +87,15 @@ private static List<Text> buildLore(Island island, Identifier identifier) {
Collections.reverse(levels);

for (Integer level : levels) {

Text levelText = Texts.of("text.neoskies.island_settings.level." + level);
Text levelText = Texts.of("island_settings/level." + level);
Map<String, Text> placeholders = new MapBuilder<String, Text>()
.put("level", levelText)
.build();

if (value == level) {
lore.add(Texts.of(Text.translatable("text.neoskies.island_settings.selected"), placeholders));
lore.add(Text.empty().setStyle(Style.EMPTY.withItalic(false)).append(Texts.of(Text.translatable("island_settings/selected"), placeholders)));
} else {
lore.add(Texts.of(Text.translatable("text.neoskies.island_settings.unselected"), placeholders));
lore.add(Text.empty().setStyle(Style.EMPTY.withItalic(false)).append(Texts.of(Text.translatable("island_settings/unselected"), placeholders)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

import com.awakenedredstone.neoskies.config.MainConfig;
import com.awakenedredstone.neoskies.logic.Skylands;
import com.awakenedredstone.neoskies.util.Texts;
import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import com.awakenedredstone.neoskies.SkylandsMain;
import com.awakenedredstone.neoskies.command.admin.*;
import com.awakenedredstone.neoskies.command.island.*;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

import java.util.Set;

import static com.awakenedredstone.neoskies.command.utils.CommandUtils.adminNode;
import static com.awakenedredstone.neoskies.command.utils.CommandUtils.registerAdmin;

Expand Down Expand Up @@ -53,11 +58,36 @@ private static void registerAdminCommands(CommandDispatcher<ServerCommandSource>
registerAdmin(dispatcher, adminNode()
.then(CommandManager.literal("reload")
.executes(context -> {
context.getSource().sendFeedback(() -> Text.translatable("message.neoskies.reload"), true);
context.getSource().sendFeedback(() -> Texts.prefixed(Text.translatable("commands.neoskies.reload")), true);
Skylands.getConfig().load();
return 1;
})
)
);

registerAdmin(dispatcher, adminNode()
.then(CommandManager.literal("bypass")
.executes(context -> {
ServerCommandSource source = context.getSource();
if (!source.isExecutedByPlayer()) {
source.sendError(Texts.prefixed(Text.translatable("commands.neoskies.error.player_only")));
return 0;
}

ServerPlayerEntity player = source.getPlayer();

Set<PlayerEntity> protectionBypass = SkylandsMain.PROTECTION_BYPASS;
boolean overrideMode = protectionBypass.contains(player);
if (overrideMode) {
protectionBypass.remove(player);
source.sendFeedback(() -> Texts.prefixed(Text.translatable("commands.neoskies.admin.bypass.disable")), true);
} else {
protectionBypass.add(player);
source.sendFeedback(() -> Texts.prefixed(Text.translatable("commands.neoskies.admin.bypass.enable")), true);
}
return 1;
})
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,40 @@ public class HubCommands {

public static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
register(dispatcher, node()
.then(literal("hub")
.requires(Permissions.require("neoskies.teleport.hub", true))
.executes(context -> {
var source = context.getSource();
var player = source.getPlayer();
MinecraftServer server = source.getServer();
if (player != null) {
HubCommands.visit(player, server);
}
return 1;
})
)
.then(literal("hub")
.requires(Permissions.require("neoskies.teleport.hub", true))
.executes(context -> {
var source = context.getSource();
var player = source.getPlayer();
MinecraftServer server = source.getServer();
if (player != null) {
HubCommands.visit(player, server);
}
return 1;
})
)
);

registerAdmin(dispatcher, adminNode()
.then(literal("hub").requires(Permissions.require("neoskies.admin.hub", 4))
.then(literal("pos").requires(Permissions.require("neoskies.admin.hub.pos", 4))
.then(argument("position", blockPos()).executes(context -> {
var pos = BlockPosArgumentType.getBlockPos(context, "position");
var source = context.getSource();
HubCommands.setPos(pos, source);
return 1;
})))
.then(literal("protection").requires(Permissions.require("neoskies.admin.hub.protection", 4))
.executes(context -> {
HubCommands.toggleProtection(context.getSource());
return 1;
})
)
)
.then(literal("hub").requires(Permissions.require("neoskies.admin.hub", 4))
.then(literal("pos").requires(Permissions.require("neoskies.admin.hub.pos", 4))
.then(argument("position", blockPos()).executes(context -> {
var pos = BlockPosArgumentType.getBlockPos(context, "position");
var source = context.getSource();
HubCommands.setPos(pos, source);
return 1;
}))
).then(literal("protection").requires(Permissions.require("neoskies.admin.hub.protection", 4))
.executes(context -> {
HubCommands.toggleProtection(context.getSource());
return 1;
})
)/*.then(literal("settings").requires(Permissions.require("neoskies.admin.hub.settings", 4))
.executes(context -> {
})
)*/
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static int view(ServerCommandSource source) {
Block block1 = Registries.BLOCK.get(block);
ItemStack stack = block1.asItem().getDefaultStack();
GuiElementBuilder builder = GuiElementBuilder.from(stack.isEmpty() ? new ItemStack(Items.BARRIER) : stack)
.hideFlags()
.hideDefaultTooltip()
.addLoreLine(Texts.of("x%d blocks".formatted(count)))
.addLoreLine(Texts.of("%d points".formatted(points * count)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private static int execute(ServerCommandSource source) {
}

ServerPlayerEntity player = source.getPlayer();
assert player != null;

int permissionLevel = player.getPermissionLevel();

Expand All @@ -63,7 +62,7 @@ private static int execute(ServerCommandSource source) {
};
final Consumer<SlotHolder> consumer = slotHolder -> {
Optional<Island> islandOptional = SkylandsAPI.getIslandByPlayer(player);
UIUtils.fillGui(slotHolder, new CBGuiElementBuilder(Items.BLACK_STAINED_GLASS_PANE).setName(Text.empty()).build());
UIUtils.fillGui(slotHolder, new CBGuiElementBuilder(Items.BLACK_STAINED_GLASS_PANE).setName(Text.empty()).hideTooltip().build());
if (Permissions.check(player, "neoskies.teleport.hub", true)) {
slotHolder.setSlot(10, new CBGuiElementBuilder(Items.BEACON).setName(Texts.of("item_name.neoskies.hub"))
.setCallback((index, type, action, gui) -> {
Expand All @@ -86,15 +85,15 @@ private static int execute(ServerCommandSource source) {
if (Permissions.check(player, "neoskies.island.settings", true)) {
slotHolder.setSlot(12, new CBGuiElementBuilder(Items.REDSTONE).setName(Texts.of("item_name.neoskies.island_settings"))
.setCallback((index, type, action, gui) -> {
gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
new IslandSettingsGui(islandOptional.get(), gui).openGui(player);
})
.build());
}
} else if (Permissions.check(player, "neoskies.island.create", true)) {
slotHolder.setSlot(11, new CBGuiElementBuilder(Items.OAK_SAPLING).setName(Texts.of("item_name.neoskies.create"))
.setCallback((index, type, action, gui) -> {
gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
CreateCommand.run(player);
ref.dirty = true;
})
Expand All @@ -107,7 +106,7 @@ private static int execute(ServerCommandSource source) {
slotHolder.setSlot(slotHolder.getSize() - 2, new CBGuiElementBuilder(item).setName(Texts.of("item_name.neoskies.protection_bypass"))
.addLoreLine(Texts.of("text.neoskies.protection_bypass", map -> map.put("value", String.valueOf(overrideMode))))
.setCallback((index, type, action, gui) -> {
gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1);
if (overrideMode) protectionBypass.remove(player);
else protectionBypass.add(player);
ref.dirty = true;
Expand Down Expand Up @@ -135,7 +134,7 @@ private static int execute(ServerCommandSource source) {
});

guiBuilder.build(player).open();
player.playSound(SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.MASTER, 0.4f, 1.2f);
player.playSoundToPlayer(SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.MASTER, 0.4f, 1.2f);
return 1;
}
}
Loading

0 comments on commit bd89ca4

Please sign in to comment.