Skip to content

Commit

Permalink
Merge branch 'dev/feature' into feature/default-comparators
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky authored Dec 18, 2024
2 parents 1266a55 + 349cb58 commit 24807f1
Show file tree
Hide file tree
Showing 32 changed files with 1,053 additions and 409 deletions.
58 changes: 37 additions & 21 deletions src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -64,27 +65,28 @@ public class SkriptCommand implements CommandExecutor {
private static final String CONFIG_NODE = "skript command";
private static final ArgsMessage m_reloading = new ArgsMessage(CONFIG_NODE + ".reload.reloading");

// TODO /skript scripts show/list - lists all enabled and/or disabled scripts in the scripts folder and/or subfolders (maybe add a pattern [using * and **])
// TODO document this command on the website
private static final CommandHelp SKRIPT_COMMAND_HELP = new CommandHelp("<gray>/<gold>skript", SkriptColor.LIGHT_CYAN, CONFIG_NODE + ".help")
.add(new CommandHelp("reload", SkriptColor.DARK_CYAN)
.add("all")
.add("config")
.add("aliases")
.add("scripts")
.add("<script>")
).add(new CommandHelp("enable", SkriptColor.DARK_CYAN)
.add("all")
.add("<script>")
).add(new CommandHelp("disable", SkriptColor.DARK_CYAN)
.add("all")
.add("<script>")
).add(new CommandHelp("update", SkriptColor.DARK_CYAN)
.add("check")
.add("changes")
.add("download")
).add("info"
).add("help");
.add(new CommandHelp("reload", SkriptColor.DARK_RED)
.add("all")
.add("config")
.add("aliases")
.add("scripts")
.add("<script>")
).add(new CommandHelp("enable", SkriptColor.DARK_RED)
.add("all")
.add("<script>")
).add(new CommandHelp("disable", SkriptColor.DARK_RED)
.add("all")
.add("<script>")
).add(new CommandHelp("update", SkriptColor.DARK_RED)
.add("check")
.add("changes")
)
.add("list")
.add("show")
.add("info")
.add("help");

static {
// Add command to generate documentation
Expand Down Expand Up @@ -360,8 +362,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
updater.updateCheck(sender);
} else if (args[1].equalsIgnoreCase("changes")) {
updater.changesCheck(sender);
} else if (args[1].equalsIgnoreCase("download")) {
updater.updateCheck(sender);
}
} else if (args[0].equalsIgnoreCase("info")) {
info(sender, "info.aliases");
Expand Down Expand Up @@ -449,6 +449,22 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
})
);
} else if (args[0].equalsIgnoreCase("list") || args[0].equalsIgnoreCase("show")) {
info(sender, "list.enabled.header");
ScriptLoader.getLoadedScripts().stream()
.map(script -> script.getConfig().getFileName())
.forEach(name -> info(sender, "list.enabled.element", name));
info(sender, "list.disabled.header");
ScriptLoader.getDisabledScripts().stream()
.flatMap(file -> {
if (file.isDirectory()) {
return Arrays.stream(file.listFiles());
}
return Arrays.stream(new File[]{file});
})
.map(File::getPath)
.map(path -> path.substring(Skript.getInstance().getScriptsFolder().getPath().length() + 1))
.forEach(path -> info(sender, "list.disabled.element", path));
} else if (args[0].equalsIgnoreCase("help")) {
SKRIPT_COMMAND_HELP.showHelp(sender);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
if (args[0].equalsIgnoreCase("update") && args.length == 2) {
options.add("check");
options.add("changes");
options.add("download");
} else if (args[0].matches("(?i)(reload|disable|enable)") && args.length >= 2) {
File scripts = Skript.getInstance().getScriptsFolder();
String scriptsPathString = scripts.toPath().toString();
Expand Down Expand Up @@ -116,6 +115,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
options.add("enable");
options.add("disable");
options.add("update");
options.add("list");
options.add("show");
options.add("info");
if (Documentation.getDocsTemplateDirectory().exists())
options.add("gen-docs");
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/ch/njol/skript/classes/Changer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ public interface Changer<T> {

enum ChangeMode {
ADD, SET, REMOVE, REMOVE_ALL, DELETE, RESET;

public boolean supportsKeyedChange() {
return this == SET;
// ADD could be supported in future
}

}

/**
* Tests whether this changer supports the given mode, and if yes what type(s) it expects the elements of <code>delta</code> to be.
* <p>
Expand Down
181 changes: 31 additions & 150 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
@@ -1,200 +1,66 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.classes.data;

import java.time.Duration;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.Aliases;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.InventoryUtils;
import ch.njol.skript.command.CommandEvent;
import ch.njol.skript.events.bukkit.ScriptEvent;
import ch.njol.skript.events.bukkit.SkriptStartEvent;
import ch.njol.skript.events.bukkit.SkriptStopEvent;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.BlockStateBlock;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.DelayedChangeBlock;
import ch.njol.skript.util.Direction;
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Getter;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.Color;
import ch.njol.skript.util.SkriptColor;
import ch.njol.skript.util.ColorRGB;
import ch.njol.skript.util.*;
import ch.njol.skript.util.slot.InventorySlot;
import ch.njol.skript.util.slot.Slot;
import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
import com.destroystokyo.paper.event.entity.EndermanAttackPlayerEvent;
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import io.papermc.paper.event.entity.EntityMoveEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import io.papermc.paper.event.player.PlayerTradeEvent;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.FireworkEffect;
import org.bukkit.GameMode;
import org.bukkit.Keyed;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.AbstractVillager;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFertilizeEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.block.BellRingEvent;
import org.bukkit.event.block.BellResonateEvent;
import org.bukkit.entity.*;
import org.bukkit.event.block.*;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.entity.EntityTransformEvent;
import org.bukkit.event.entity.EntityTransformEvent.TransformReason;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.entity.HorseJumpEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.DragType;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerItemMendEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupArrowEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerExpCooldownChangeEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason;
import org.bukkit.event.player.PlayerQuitEvent.QuitReason;
import org.bukkit.event.player.PlayerRiptideEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.vehicle.*;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.event.weather.WeatherEvent;
import org.bukkit.event.world.ChunkEvent;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.event.world.WorldEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.Recipe;
import org.bukkit.event.world.*;
import org.bukkit.inventory.*;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author Peter Güttinger
*/
Expand Down Expand Up @@ -2041,5 +1907,20 @@ public Timespan get(PlayerExpCooldownChangeEvent event) {
}
}, EventValues.TIME_PAST);

// VehicleMoveEvent
EventValues.registerEventValue(VehicleMoveEvent.class, Location.class, new Getter<>() {
@Override
public Location get(VehicleMoveEvent event) {
return event.getTo();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(VehicleMoveEvent.class, Location.class, new Getter<>() {
@Override
public Location get(VehicleMoveEvent event) {
return event.getFrom();
}
}, EventValues.TIME_PAST);

}

}
Loading

0 comments on commit 24807f1

Please sign in to comment.