Skip to content

Commit

Permalink
General fixes for the next release.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Feb 18, 2024
1 parent 7e4cc5e commit 5f1d012
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 52 deletions.
9 changes: 7 additions & 2 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.lokka30.phantomworlds;

import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.argument.ArgumentKey;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
import me.lokka30.microlib.files.YamlConfigFile;
import me.lokka30.microlib.maths.QuickTimer;
Expand Down Expand Up @@ -228,10 +229,14 @@ void registerCommands() {

this.command = LiteBukkitFactory.builder()
.commands(new PWCommand())
.settings(settings -> settings
.fallbackPrefix("phantomworlds")
.nativePermissions(false)
)
.argument(GameMode.class, new GamemodeParameter())
.argument(PortalType.class, new PortalParameter())
.argument(List.class, new PotionEffectParameter())
.argument(List.class, new SettingParameter())
.argument(String.class, ArgumentKey.of("world-setting"), new SettingParameter())
.argument(String.class, ArgumentKey.of("potion-effects"), new PotionEffectParameter())
.argument(World.class, new AliasWorldParameter())
.argument(WorldFolder.class, new WorldFolderParameter()).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* @author creatorfromhell
* @since 2.0.5.0
*/
@Command(name = "phantomworlds", aliases = "pw")
@Command(name = "phantomworlds", aliases = {"pw"})
public class PWCommand {

@Execute(name = "backup", aliases = {"archive", "bu"})
Expand All @@ -70,7 +70,7 @@ public void backup(@Context CommandSender commandSender, @OptionalArg("world") f
@Execute(name = "create", aliases = {"+", "new"})
@Permission("phantomworlds.command.phantomworlds.create")
@Description("command.phantomworlds.help.create")
public void create(@Context CommandSender commandSender, @Arg("world name") final String name, @Arg("environment")World.Environment environment, @OptionalArg("world-setting") List<String> settings) {
public void create(@Context CommandSender commandSender, @Arg("world name") final String name, @Arg("environment")World.Environment environment, @Arg("world-setting") List<String> settings) {
CreateCommand.onCommand(commandSender, name, environment, settings);
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public void reload(@Context CommandSender commandSender) {
@Execute(name = "set effects", aliases = {"set eff"})
@Permission("phantomworlds.command.phantomworlds.set.effects")
@Description("command.phantomworlds.help.seteffects")
public void setEffects(@Context CommandSender commandSender, @Arg("world") World world, @OptionalArg("potion-effects") List<String> effects) {
public void setEffects(@Context CommandSender commandSender, @Arg("world") World world, @Arg("potion-effects") List<String> effects) {
SetEffectsCommand.onCommand(commandSender, world, effects);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -36,27 +35,24 @@
* @author creatorfromhell
* @since 2.0.5.0
*/
public class PotionEffectParameter extends ArgumentResolver<CommandSender, List> {
public class PotionEffectParameter extends ArgumentResolver<CommandSender, String> {

private static final List<String> POTION_EFFECTS = new ArrayList<>();

static {
for (PotionEffectType value : PotionEffectType.values()) {
POTION_EFFECTS.add(value.getName());
for(PotionEffectType value : PotionEffectType.values()) {
POTION_EFFECTS.add(value.getKey() + ",duration,amplifier");
POTION_EFFECTS.add(value.getKey() + ",-1,1");
}
}

@Override
protected ParseResult<List> parse(Invocation<CommandSender> invocation, Argument<List> context, String argument) {
return ParseResult.success(Collections.singletonList(argument));
protected ParseResult<String> parse(Invocation<CommandSender> invocation, Argument<String> context, String argument) {
return ParseResult.success(argument);
}

@Override
public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<List> argument, SuggestionContext context) {

if(argument.getKeyName().equalsIgnoreCase("potion-effects")) {
return SuggestionResult.of(POTION_EFFECTS);
}
return SuggestionResult.of(new ArrayList<>());
public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<String> argument, SuggestionContext context) {
return SuggestionResult.of(POTION_EFFECTS);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.lokka30.phantomworlds.commandsredux.params;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -26,28 +26,20 @@
import me.lokka30.phantomworlds.PhantomWorlds;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Setting
* SettingParameterRedux
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class SettingParameter extends ArgumentResolver<CommandSender, List> {
public class SettingParameter extends ArgumentResolver<CommandSender, String> {
@Override
protected ParseResult<List> parse(Invocation<CommandSender> invocation, Argument<List> context, String argument) {
return ParseResult.success(Collections.singletonList(argument));
protected ParseResult<String> parse(Invocation<CommandSender> invocation, Argument<String> context, String argument) {
return ParseResult.success(argument);
}

@Override
public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<List> argument, SuggestionContext context) {

if(argument.getKeyName().equalsIgnoreCase("world-setting")) {
return SuggestionResult.of(PhantomWorlds.createTabs);
}
return SuggestionResult.of(new ArrayList<>());
public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<String> argument, SuggestionContext context) {
return SuggestionResult.of(PhantomWorlds.createTabs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,47 @@ public static void onCommand(final CommandSender sender, final World world, fina
return;
}

final StringBuilder eff = new StringBuilder();

final World finalWorld = (world == null)? ((Player)sender).getWorld() : world;

final String cfgPath = "worlds-to-load." + finalWorld.getName();
if(PhantomWorlds.instance().data.getConfig().contains(cfgPath)) {
//PhantomWorlds manages this world so let's set the spawn here for better accuracy.
PhantomWorlds.instance().data.getConfig().set(cfgPath + ".effects", String.join(", ", effects));

try {
PhantomWorlds.instance().data.save();
} catch(final IOException ex) {
throw new RuntimeException(ex);

for(String effString : effects) {

if(eff.length() > 0) {
eff.append(", ");
}

final String[] effSettings = effString.split(",");

int duration = -1;
if(effSettings.length > 1) {
try {
duration = Integer.parseInt(effSettings[1]);
} catch(NumberFormatException ignore) {
}
}


int amplifier = 1;
if(effSettings.length > 2) {
try {
amplifier = Integer.parseInt(effSettings[2]);
} catch(NumberFormatException ignore) {
}
}

eff.append(effSettings[0]);

PhantomWorlds.instance().data.getConfig().set(cfgPath + ".effects." + effSettings[0] + ".duration", duration);
PhantomWorlds.instance().data.getConfig().set(cfgPath + ".effects." + effSettings[0] + ".amplifier", amplifier);
}

try {
PhantomWorlds.instance().data.save();
} catch(final IOException ex) {
throw new RuntimeException(ex);
}

(new MultiMessage(
Expand All @@ -62,7 +90,7 @@ public static void onCommand(final CommandSender sender, final World world, fina
PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
true),
new MultiMessage.Placeholder("world", finalWorld.getName(), false),
new MultiMessage.Placeholder("effects", effects.toString(), false)
new MultiMessage.Placeholder("effects", eff.toString(), false)
))).send(sender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import me.lokka30.phantomworlds.PhantomWorlds;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
Expand Down Expand Up @@ -61,26 +62,32 @@ public void onChangeWorld(PlayerChangedWorldEvent event) {
event.getPlayer().setGameMode(mode);
}

System.out.println("Effects Checks");

final String cfgPrevPath = "worlds-to-load." + event.getFrom().getName();
if(PhantomWorlds.instance().getConfig().contains(cfgPrevPath + ".effects") &&
PhantomWorlds.instance().getConfig().isConfigurationSection(cfgPrevPath + ".effects")) {
for(final String effName : PhantomWorlds.instance().getConfig().getConfigurationSection(cfgPrevPath + ".effects").getKeys(false)) {
if(PhantomWorlds.instance().data.getConfig().contains(cfgPrevPath + ".effects") &&
PhantomWorlds.instance().data.getConfig().isConfigurationSection(cfgPrevPath + ".effects")) {
for(final String effName : PhantomWorlds.instance().data.getConfig().getConfigurationSection(cfgPrevPath + ".effects").getKeys(false)) {

final PotionEffectType type = PotionEffectType.getByName(effName);
final PotionEffectType type = PotionEffectType.getByKey(NamespacedKey.fromString(effName));
if(type != null) {
event.getPlayer().removePotionEffect(type);
}
}
}

if(PhantomWorlds.instance().getConfig().contains(cfgPath + ".effects") &&
PhantomWorlds.instance().getConfig().isConfigurationSection(cfgPath + ".effects") && !event.getPlayer().hasPermission("phantomworlds.world.bypass.effects")) {
if(PhantomWorlds.instance().data.getConfig().contains(cfgPath + ".effects") &&
PhantomWorlds.instance().data.getConfig().isConfigurationSection(cfgPath + ".effects") && !event.getPlayer().hasPermission("phantomworlds.world.bypass.effects")) {

System.out.println("Apply effects.");

for(final String effName : PhantomWorlds.instance().data.getConfig().getConfigurationSection(cfgPath + ".effects").getKeys(false)) {
final int duration = PhantomWorlds.instance().data.getConfig().getInt(cfgPath + ".effects." + effName + ".duration", -1);
final int amplifier = PhantomWorlds.instance().data.getConfig().getInt(cfgPath + ".effects." + effName + ".amplifier", 1);

for(final String effName : PhantomWorlds.instance().getConfig().getConfigurationSection(cfgPath + ".effects").getKeys(false)) {
final int duration = PhantomWorlds.instance().getConfig().getInt(cfgPath + ".effects." + effName, 60);
final int amplifier = PhantomWorlds.instance().getConfig().getInt(cfgPath + ".effects." + effName, 1);

final PotionEffectType type = PotionEffectType.getByName(effName);
System.out.println("Apply effect: " + effName);
final PotionEffectType type = PotionEffectType.getByKey(NamespacedKey.fromString(effName));
if(type != null) {
final PotionEffect effect = new PotionEffect(type, duration, amplifier);
event.getPlayer().addPotionEffect(effect);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ command:
- '&8 &m->&b /%label% set whitelist <world> <whitelist(true/false)> &8- &7set whether there is a whitelist for this world or not.'
- '&8 &m->&b /%label% setspawn &8- &7set the spawnpoint of a world'
- '&8 &m->&b /%label% delete &8- &7delete a world'
- '&8 &m->&b /%label% backup &8- &backup a world'
- '&8 &m->&b /%label% backup <world> &8- &7Backup a world'
- '&8 &m->&b /%label% unload &8- &7unload a loaded world'
- '&8 &m->&b /%label% load &8- &7load an unloaded world'
- '&8 &m->&b /%label% reload &8- &7reload all config & data files'
Expand Down
45 changes: 45 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ permissions:
phantomworlds.knows-vanished-users: true
phantomworlds.command.phantomworlds.*: true


phantomworlds.world.bypass.gamemode:
default: op
description: 'Used to bypass the gamemode setting for worlds.'


phantomworlds.world.bypass.effects:
default: op
description: 'Used to bypass the effects setting for worlds.'

phantomworlds.knows-vanished-users:
default: op
description: 'Users with this permission will ignore the status of vanished players when using commands from PhantomWorlds, such as in tab-completion suggestions.'
Expand All @@ -37,12 +47,19 @@ permissions:
description: 'Ability to run all /pw commands.'
children:
phantomworlds.command.phantomworlds: true
phantomworlds.command.phantomworlds.backup: true
phantomworlds.command.phantomworlds.compatibility: true
phantomworlds.command.phantomworlds.create: true
phantomworlds.command.phantomworlds.debug: true
phantomworlds.command.phantomworlds.import: true
phantomworlds.command.phantomworlds.info: true
phantomworlds.command.phantomworlds.list: true
phantomworlds.command.phantomworlds.load: true
phantomworlds.command.phantomworlds.setspawn: true
phantomworlds.command.phantomworlds.set.effects: true
phantomworlds.command.phantomworlds.set.gamemode: true
phantomworlds.command.phantomworlds.set.portal: true
phantomworlds.command.phantomworlds.set.whitelist: true
phantomworlds.command.phantomworlds.teleport: true
phantomworlds.command.phantomworlds.spawn: true
phantomworlds.command.phantomworlds.unload: true
Expand All @@ -52,6 +69,10 @@ permissions:
default: op
description: 'Ability to run /pw'

phantomworlds.command.phantomworlds.backup:
default: op
description: 'Ability to run /pw backup'

phantomworlds.command.phantomworlds.compatibility:
default: op
description: 'Ability to run /pw compatibility'
Expand All @@ -64,6 +85,10 @@ permissions:
default: op
description: 'Ability to run /pw create'

phantomworlds.command.phantomworlds.import:
default: op
description: 'Ability to run /pw import'

phantomworlds.command.phantomworlds.info:
default: true
description: 'Ability to run /pw info'
Expand All @@ -72,10 +97,30 @@ permissions:
default: op
description: 'Ability to run /pw list'

phantomworlds.command.phantomworlds.load:
default: op
description: 'Ability to run /pw load'

phantomworlds.command.phantomworlds.setspawn:
default: op
description: 'Ability to run /pw setspawn'

phantomworlds.command.phantomworlds.set.effects:
default: op
description: 'Ability to run /pw set effects'

phantomworlds.command.phantomworlds.set.gamemode:
default: op
description: 'Ability to run /pw set gamemode'

phantomworlds.command.phantomworlds.set.portal:
default: op
description: 'Ability to run /pw set portal'

phantomworlds.command.phantomworlds.set.whitelist:
default: op
description: 'Ability to run /pw set whitelist'

phantomworlds.command.phantomworlds.teleport:
default: op
description: 'Ability to run /pw teleport'
Expand Down

0 comments on commit 5f1d012

Please sign in to comment.