Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia Support + Platform Abstraction #14

Merged
merged 77 commits into from
Jun 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
c7d50ab
Abstract away basic bukkit api, incomplete
CoPokBl May 23, 2024
0e824e4
Abstract blocks and effects and enchantments
CoPokBl May 24, 2024
a21d068
More item data, tester, player invs, general improvements
CoPokBl May 24, 2024
168f864
More meta, nbt, general movement towards abstraction
CoPokBl May 24, 2024
3b14263
IT BUILDS
CoPokBl May 24, 2024
74cd83e
The plugin now enables
CoPokBl May 24, 2024
f0298d6
Make everything work on regular bukkit
CoPokBl May 24, 2024
9a7ff27
Abstract logger, fix depends, fix tp, start implement scheduler, fix …
CoPokBl May 24, 2024
b56a0a2
Folia partial support, fix bugs with stuff
CoPokBl May 25, 2024
16fa4b4
Start implementing events, more fixes
CoPokBl May 25, 2024
86167a5
Implement all events
CoPokBl May 26, 2024
62878ba
Fix resource overlap warns
CoPokBl May 26, 2024
3a2db3d
Abstract commands and fix many commands
CoPokBl May 26, 2024
1916337
New config system, various fixes, vault signs
CoPokBl May 26, 2024
ed4944e
Remove /music todo
CoPokBl May 26, 2024
77b19fe
Attempt fix cchests config
CoPokBl May 27, 2024
7646e67
Attempt reflection janky fix
CoPokBl May 28, 2024
5923211
Full normal non janky CChests saving
CoPokBl May 30, 2024
f4c8b4a
Start working on BukkitConfigMigrator
CoPokBl May 30, 2024
70b234a
Finish config migrator
CoPokBl May 31, 2024
77efd74
Potions saving to YML (untested)
CoPokBl Jun 3, 2024
b74915f
Work towards fixing Potion saving in CChests
CoPokBl Jun 5, 2024
cc66a63
Stop events messing with the current cancellation state and messing u…
CoPokBl Jun 5, 2024
f631b91
Made EsSerialisableItemStack work with any NBT data/meta, and fixed b…
Calcilore Jun 15, 2024
41cd4e0
Relocations, fix EsSerialisableItemStack potions and folia bugs
CoPokBl Jun 15, 2024
aff8e2f
Compatability improvemetns
Calcilore Jun 15, 2024
f2cc2de
Fix /editsign target block broken null
CoPokBl Jun 16, 2024
f2884ef
Testing, fix registry old version issues
CoPokBl Jun 16, 2024
8a17da9
Fix give bug where conflict and default config override actual becaus…
CoPokBl Jun 16, 2024
410ed0f
Fix when EquipmentSlots weren't used in PlayerInventory (1.12 done)
CoPokBl Jun 17, 2024
8594683
Fix sounds not existing in old versions and fix old enchants not bein…
CoPokBl Jun 17, 2024
4dd563e
Equipment slots and brainless potion implement
CoPokBl Jun 17, 2024
1e1bf68
Fix stuff for 1.7.10
CoPokBl Jun 17, 2024
dafc410
Moved away for using Strings for Materials, Enchantments and Effects …
Calcilore Jun 18, 2024
d3e815f
Fixed name of Helpers package for bukkit
CoPokBl Jun 18, 2024
64cc35f
Added EsSound for sound effects (some old sounds in old versions do n…
Calcilore Jun 19, 2024
517943f
spelling and grammar in BukkitSoundEnumConverter
CoPokBl Jun 19, 2024
3eed408
Update README.md
CoPokBl Jun 21, 2024
42bcef2
Fix movement away from String ids from breaking serialisation
CoPokBl Jun 21, 2024
3556fb0
Refactor, fix bugs that never surfaced and fixed getinfo bug from EsE…
CoPokBl Jun 21, 2024
da96981
Added missing commands to /estools test
Calcilore Jun 21, 2024
4f72b66
Fixed HideFlags error when you are not holding anything
Calcilore Jun 21, 2024
7099bed
Fixed Ench error when you are not holding anything
Calcilore Jun 21, 2024
978a2aa
Fixed GetInfo amplifier starting at 0
Calcilore Jun 21, 2024
5fb4562
Fix dumb Folia in bukkit error
CoPokBl Jun 21, 2024
f39d085
Fixed setItem with equipment slot checking the wrong version
Calcilore Jun 21, 2024
5b3c593
Fixed give commands breaking in 1.13 specifically
Calcilore Jun 21, 2024
b49ada6
Fix dumb Folia in bukkit errors again
CoPokBl Jun 21, 2024
545fe1e
Merge remote-tracking branch 'origin/folia' into folia
CoPokBl Jun 21, 2024
51d98d2
Fix signs and remove Vault support
CoPokBl Jun 21, 2024
d80407d
Fixed give commands breaking in 1.13 specifically
Calcilore Jun 21, 2024
cc1b2a7
Fix mount error on invalid rider
CoPokBl Jun 21, 2024
6349fd0
Fixed getInventory having wrong version for compat in 1.9-1.10
Calcilore Jun 21, 2024
2acd27e
Fixed /back not seeing /tp as a valid teleport reason
Calcilore Jun 21, 2024
4f2696a
Fix tester invalid coords
CoPokBl Jun 21, 2024
264450c
Merge remote-tracking branch 'origin/folia' into folia
CoPokBl Jun 21, 2024
ce9a4f3
Fix get entity failing
CoPokBl Jun 21, 2024
10f953c
Fixed potion amplifiers starting at 1 in older versions
Calcilore Jun 21, 2024
6695ab0
Fix locations on old versions (and remove unneeded code), test versions
CoPokBl Jun 21, 2024
659bf7a
Change SemanticVersion methods
CoPokBl Jun 21, 2024
df967eb
Remove Vault softdepend
CoPokBl Jun 21, 2024
e14e460
Fix 1.4 support, events not working
CoPokBl Jun 22, 2024
bc489a6
Fix 1.3 support, fix setmaxhealth min version
CoPokBl Jun 22, 2024
f51ffd5
Fix 1.2 support, move Sounds away
CoPokBl Jun 22, 2024
2666265
Fix 1.1 support, move more events and methods
CoPokBl Jun 23, 2024
786a86f
Add version specific tests
CoPokBl Jun 23, 2024
b4adb1b
Fix non player send message bugs on old versions
CoPokBl Jun 23, 2024
9bc8e87
Make /estools reset and reload work properly
CoPokBl Jun 23, 2024
98c2f56
Fix potions in pre 1.4 and move funcs for 1.0 support
CoPokBl Jun 23, 2024
e136d34
Fix /rename not checking if meta is null, also removed MetaHandler wh…
CoPokBl Jun 23, 2024
895ad71
Fix events not behaving properly on old versions
CoPokBl Jun 23, 2024
4f64462
Change version of getClickedInventory being added
CoPokBl Jun 23, 2024
ff2a4ae
Fix version where potion amp is limited
CoPokBl Jun 23, 2024
f3effc3
Changed the version where InventoryView.getInventory(int slot) was ad…
Calcilore Jun 23, 2024
4774cc5
Fix folia creating BukkitPotion
CoPokBl Jun 23, 2024
fb04e42
Added old version support for Signs and changed SemanticVersion .getS…
Calcilore Jun 23, 2024
b800fb3
Merge branch 'master' into folia
CoPokBl Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Abstract blocks and effects and enchantments
CoPokBl committed May 24, 2024
commit 0e824e4848ae57c66a97ae8a1aecdcf0bf6ea5ea
25 changes: 9 additions & 16 deletions src/main/java/net/serble/estools/Commands/EditSign.java
Original file line number Diff line number Diff line change
@@ -2,16 +2,11 @@

import net.serble.estools.EsToolsCommand;
import net.serble.estools.Main;
import net.serble.estools.ServerApi.Interfaces.EsCommandSender;
import net.serble.estools.ServerApi.Interfaces.EsPlayer;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.SignSide;
import net.serble.estools.ServerApi.Interfaces.*;

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

// TODO: Command incomplete
public class EditSign extends EsToolsCommand {
private static final String usage = genUsage("/editsign <line number> [line]");

@@ -28,14 +23,14 @@ public boolean execute(EsCommandSender sender, String[] args) {

EsPlayer p = (EsPlayer) sender;

Block signB = p.getTargetBlock();
EsBlock signB = p.getTargetBlock();

if (signB == null || !(signB.getState() instanceof Sign)) {
if (!(signB instanceof EsSign)) {
send(sender, "&cYou must be looking at a sign!");
return false;
}

Sign sign = (Sign) signB.getState();
EsSign sign = (EsSign) signB;

switch (args[0].toLowerCase()) {
case "glow":
@@ -77,10 +72,9 @@ public boolean execute(EsCommandSender sender, String[] args) {
String lineText = translate(lineTextBuilder.toString()).trim();

if (Main.minecraftVersion.getMinor() >= 20) {
SignSide side = sign.getTargetSide(p);
EsSignSide side = sign.getTargetSide(p);
side.setLine(lineNum - 1, lineText);
} else {
//noinspection deprecation
sign.setLine(lineNum - 1, lineText);
}
sign.update();
@@ -113,10 +107,9 @@ public List<String> tabComplete(EsCommandSender sender, String[] args, String lA
return tab;
}

@SuppressWarnings("deprecation")
public boolean setGlow(Sign sign, Player p, boolean glow) {
if (Main.majorVersion >= 20) {
SignSide side = sign.getTargetSide(p);
public boolean setGlow(EsSign sign, EsPlayer p, boolean glow) {
if (Main.minecraftVersion.getMinor() >= 20) {
EsSignSide side = sign.getTargetSide(p);

if (side.isGlowingText() == glow) {
if (glow) {
@@ -130,7 +123,7 @@ public boolean setGlow(Sign sign, Player p, boolean glow) {

side.setGlowingText(glow);
}
else if (Main.majorVersion >= 17) {
else if (Main.minecraftVersion.getMinor() >= 17) {
if (sign.isGlowingText() == glow) {
if (glow) {
send(p, "&cThis sign is already &6glowing!");
25 changes: 11 additions & 14 deletions src/main/java/net/serble/estools/Commands/Eff.java
Original file line number Diff line number Diff line change
@@ -3,11 +3,8 @@
import net.serble.estools.Effects;
import net.serble.estools.Main;
import net.serble.estools.MultiPlayerCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import net.serble.estools.ServerApi.Interfaces.EsCommandSender;
import net.serble.estools.ServerApi.Interfaces.EsPlayer;

import java.util.ArrayList;
import java.util.List;
@@ -17,13 +14,13 @@ public class Eff extends MultiPlayerCommand {
private static final String usage = genUsage("/eff <effect> [amplifier] [duration] [players]");

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public boolean execute(EsCommandSender sender, String[] args) {
if (args.length == 0) {
send(sender, usage);
return false;
}

PotionEffectType effect = Effects.getByName(args[0]);
String effect = Effects.getByName(args[0]);

if (effect == null) {
send(sender, "&cEffect not found!");
@@ -54,22 +51,22 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
durationStr = String.format("%s seconds", duration / 20);

if (duration == 32767) {
if (Main.majorVersion >= 19) {
if (Main.minecraftVersion.getMinor() >= 19) {
duration = -1;
}

durationStr = "forever";
}
}

ArrayList<Player> players = new ArrayList<>();
ArrayList<EsPlayer> players = new ArrayList<>();

if (args.length < 4) {
if (isNotPlayer(sender, usage)) {
return false;
}

players.add((Player)sender);
players.add((EsPlayer) sender);
} else {
players = getPlayers(sender, removeArgs(args, 3));

@@ -78,9 +75,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
}

for (Player p : players) {
for (EsPlayer p : players) {
p.removePotionEffect(effect);
p.addPotionEffect(new PotionEffect(effect, duration, amplifier));
p.addPotionEffect(effect, duration, amplifier);
}

send(sender, "&aAdded effect &6%s&a at level &6%s&a for &6%s", Effects.getName(effect), amplifier + 1, durationStr);
@@ -106,12 +103,12 @@ private int calculateDuration(String input) {
}

@Override
public List<String> tabComplete(CommandSender sender, String[] args, String lArg) {
public List<String> tabComplete(EsCommandSender sender, String[] args, String lArg) {
List<String> tab = new ArrayList<>();

switch (args.length) {
case 1:
for (Map.Entry<String, PotionEffectType> e : Effects.entrySet()) {
for (Map.Entry<String, String> e : Effects.entrySet()) {
tab.add(e.getKey().toLowerCase());
}
break;
40 changes: 13 additions & 27 deletions src/main/java/net/serble/estools/Commands/Ench.java
Original file line number Diff line number Diff line change
@@ -6,27 +6,26 @@

import net.serble.estools.Enchantments;
import net.serble.estools.Main;
import net.serble.estools.ServerApi.Interfaces.EsCommandSender;
import net.serble.estools.ServerApi.Interfaces.EsItemStack;
import net.serble.estools.ServerApi.Interfaces.EsPlayer;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import net.serble.estools.EsToolsCommand;

public class Ench extends EsToolsCommand {
private static final String usage = genUsage("/ench <enchantment> [level] [player]");

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public boolean execute(EsCommandSender sender, String[] args) {
if (args.length == 0) {
send(sender, usage);
return false;
}

ItemStack is;
EsItemStack is;

int level = 1;
if (args.length > 1) {
@@ -43,32 +42,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return false;
}

is = getMainHand(((Player) sender));
is = ((EsPlayer) sender).getMainHand();
} else {
Player p = getPlayer(sender, args[2]);
EsPlayer p = getPlayer(sender, args[2]);

if (p == null) {
return false;
}

is = getMainHand(p);
is = p.getMainHand();
}

Enchantment ench;
try {
if (Main.majorVersion > 12) {
ench = Registry.ENCHANTMENT.get(NamespacedKey.minecraft(args[0].toLowerCase()));
} else {
ench = Enchantments.getByName(args[0].toLowerCase());
}
} catch (IllegalArgumentException e) {
send(sender, usage);
return false;
}


if (ench != null && is != null) {
is.addUnsafeEnchantment(ench, level);
if (Main.server.doesEnchantmentExist(args[0].toLowerCase()) && is != null) {
is.addEnchantment(args[0].toLowerCase(), level);
send(sender, "&aEnchantment &6%s&a at level &6%s&a was added!", args[0].toLowerCase(), level);
}
else {
@@ -78,12 +64,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

@Override
public List<String> tabComplete(CommandSender sender, String[] args, String lArg) {
public List<String> tabComplete(EsCommandSender sender, String[] args, String lArg) {
List<String> tab = new ArrayList<>();

switch (args.length) {
case 1:
if (Main.majorVersion > 12) {
if (Main.minecraftVersion.getMinor() > 12) {
for (Enchantment e : Registry.ENCHANTMENT) {
tab.add(e.getKey().getKey());
}
@@ -96,7 +82,7 @@ public List<String> tabComplete(CommandSender sender, String[] args, String lArg
break;

case 3:
for (Player p : getOnlinePlayers()) {
for (EsPlayer p : Main.server.getOnlinePlayers()) {
tab.add(p.getName());
}
break;
2 changes: 1 addition & 1 deletion src/main/java/net/serble/estools/Commands/Potion.java
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ public List<String> tabComplete(CommandSender sender, String[] args, String lArg
switch (args.length) {
case 1:
if (Main.majorVersion <= 8) {
for (Map.Entry<String, PotionType> e : Effects.potionEntrySet()) {
for (Map.Entry<String, PotionType> e : Effects.getPotionList()) {
tab.add(e.getKey().toLowerCase());
}
}
40 changes: 16 additions & 24 deletions src/main/java/net/serble/estools/Effects.java
Original file line number Diff line number Diff line change
@@ -3,26 +3,22 @@
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.*;

@SuppressWarnings("deprecation")
public class Effects {
private static final Map<String, PotionEffectType> EFFECTS = new HashMap<>();
private static final Map<String, String> EFFECTS = new HashMap<>();
private static final Map<String, PotionType> POTIONS = new HashMap<>();

public static PotionEffectType getByName(String name) {
return EFFECTS.get(name.toLowerCase(Locale.ENGLISH));
public static String getByName(String name) {
return EFFECTS.get(name);
}

public static PotionType getPotionByName(String name) {
return POTIONS.get(name.toLowerCase(Locale.ENGLISH));
}

public static String getName(PotionEffectType effect) {
for (Map.Entry<String, PotionEffectType> a : EFFECTS.entrySet()) {
public static String getName(String effect) {
for (Map.Entry<String, String> a : EFFECTS.entrySet()) {
if (a.getValue().equals(effect)) {
return a.getKey();
}
@@ -31,16 +27,16 @@ public static String getName(PotionEffectType effect) {
return "invalid";
}

public static Set<Map.Entry<String, PotionEffectType>> entrySet() {
public static Set<Map.Entry<String, String>> entrySet() {
return EFFECTS.entrySet();
}

public static Set<Map.Entry<String, PotionType>> potionEntrySet() {
public static Set<Map.Entry<String, PotionType>> getPotionList() {
return POTIONS.entrySet();
}

static {
if (Main.majorVersion <= 8) { // 1.8 only potions be funky
public static void load() {
if (Main.minecraftVersion.getMinor() <= 8) { // 1.8 only potions be funky
POTIONS.put("regeneration", PotionType.REGEN);
POTIONS.put("speed", PotionType.SPEED);
POTIONS.put("fire_resistance", PotionType.FIRE_RESISTANCE);
@@ -51,16 +47,16 @@ public static Set<Map.Entry<String, PotionType>> potionEntrySet() {
POTIONS.put("slowness", PotionType.SLOWNESS);
POTIONS.put("instant_damage", PotionType.INSTANT_DAMAGE);

if (Main.majorVersion >= 4 && Main.minorVersion >= 2) { // Night vision was added in 1.4.2
if (Main.minecraftVersion.getMinor() >= 4 && Main.minecraftVersion.getMinor() >= 2) { // Night vision was added in 1.4.2
POTIONS.put("night_vision", PotionType.NIGHT_VISION);
POTIONS.put("invisibility", PotionType.INVISIBILITY);
}

if (Main.majorVersion >= 7 && Main.minorVersion >= 2) { // 1.7.2
if (Main.minecraftVersion.getMinor() >= 7 && Main.minecraftVersion.getMinor() >= 2) { // 1.7.2
POTIONS.put("water_breathing", PotionType.WATER);
}

if (Main.majorVersion >= 8) { // 1.8
if (Main.minecraftVersion.getMinor() >= 8) { // 1.8
POTIONS.put("jump_boost", PotionType.JUMP);
}
}
@@ -77,18 +73,14 @@ public static Set<Map.Entry<String, PotionType>> potionEntrySet() {
put("jump", "jump_boost");
}};

for (PotionEffectType p : PotionEffectType.values()) {
if (p == null) { // 1.1 has null values in here...
continue;
}

String name = p.getName().toLowerCase(Locale.ENGLISH);
for (String s : Main.server.getPotionEffectTypes()) {
String name = s.toLowerCase();

if (nameReplacers.containsKey(name)) {
name = nameReplacers.get(name);
}

EFFECTS.put(name, p);
EFFECTS.put(name, s.toLowerCase());
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/serble/estools/EsToolsCommand.java
Original file line number Diff line number Diff line change
@@ -117,8 +117,8 @@ public static String genUsage(String use) {
return "&r&c&lUsage: &r&c" + use.replace("\n", "\n ");
}

public static Player getPlayer(EsCommandSender sender, String name) {
Player p = Bukkit.getPlayer(name);
public static EsPlayer getPlayer(EsCommandSender sender, String name) {
EsPlayer p = Main.server.getPlayer(name);

if (p == null) {
send(sender, "&cPlayer not found.");
2 changes: 2 additions & 0 deletions src/main/java/net/serble/estools/Main.java
Original file line number Diff line number Diff line change
@@ -50,6 +50,8 @@ public void enable() {

minecraftVersion = server.getVersion();

Effects.load();

if (platform == ServerPlatform.Bukkit) {
try {
Vault.setupEconomy();
Loading