Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed May 24, 2024
1 parent a535b02 commit 60077e5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 71 deletions.
5 changes: 3 additions & 2 deletions calio/src/main/java/me/dueris/calio/CraftCalio.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public void start(boolean debug) {
file = file.replace("/", "\\");
if ((file.startsWith("data\\")) && file.endsWith(".json")) {
String fixedJsonFile = file.substring(file.indexOf("data\\"));
String namespace = fixedJsonFile.split("\\\\")[1];
String[] parts = fixedJsonFile.split("\\\\");
String namespace = parts[1];
String name = fixedJsonFile.split("\\\\")[2].split("\\\\")[0];
String key = fixedJsonFile.split("\\\\")[fixedJsonFile.split("\\\\").length - 1].replace(".json", "");
String key = fixedJsonFile.substring(fixedJsonFile.indexOf(namespace) + namespace.length() + 1).replace(".json", "").replace("\\", "/").replace(name + "/", "");
if (accessorKey.getDirectory().equalsIgnoreCase(name)) {
try (InputStream is = fileReader.getFileStream(file.replace("\\", "/"));
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
Expand Down
16 changes: 0 additions & 16 deletions origins/src/main/java/me/dueris/genesismc/OriginScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,11 @@

public class OriginScheduler {
final Plugin plugin;
private final ConcurrentLinkedQueue<Runnable> tasksOnMain = new ConcurrentLinkedQueue<>();
private final ConcurrentLinkedQueue<Runnable> tasksOffMain = new ConcurrentLinkedQueue<>();

public OriginScheduler(Plugin plugin) {
this.plugin = plugin;
}

public void onMain(Runnable runnable) {
this.tasksOnMain.add(runnable);
}

public void offMain(Runnable runnable) {
this.tasksOffMain.add(runnable);
}

public static class MainTickerThread extends BukkitRunnable implements Listener {
private final CreativeFlight flight = new CreativeFlight("creative_flight", "description", true, null, 0);
public OriginScheduler parent = new OriginScheduler(GenesisMC.getPlugin());
Expand All @@ -44,9 +34,6 @@ public String toString() {

@Override
public void run() {
ConcurrentLinkedQueue<Runnable> tasks = new ConcurrentLinkedQueue<>(parent.tasksOnMain);
parent.tasksOnMain.clear();
tasks.forEach(Runnable::run);
for (PowerType power : CraftApoli.getPowersFromRegistry()) {
power.tick(); // Allow powers to add their own BukkitRunnables
if (!power.hasPlayers()) continue;
Expand Down Expand Up @@ -82,9 +69,6 @@ public void run() {
}

public void tickAsyncScheduler() {
ConcurrentLinkedQueue<Runnable> tasks = new ConcurrentLinkedQueue<>(parent.tasksOffMain);
parent.tasksOffMain.clear();
tasks.forEach(Runnable::run);
for (Player p : PowerHolderComponent.hasPowers) {
ConcurrentLinkedQueue<PowerType> applied = PowerHolderComponent.getPowersApplied(p);
for (PowerType c : applied) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,17 @@ public void MoveBackChange(PowerUpdateEvent e) {
if (e.getPower() instanceof Inventory inventoryPower && e.getPower().getTag().equalsIgnoreCase(getTag())) {
PowerType power = e.getPower();
Player p = e.getPlayer();
GenesisMC.scheduler.parent.onMain(() -> {
ArrayList<ItemStack> vaultItems = getItems(p, power.getTag());
for (ItemStack item : new ArrayList<>(vaultItems)) {
if (item != null && item.getType() != Material.AIR) {
if (inventoryPower.recoverable) {
p.getWorld().dropItemNaturally(p.getLocation(), item);
}
vaultItems.remove(item);
ArrayList<ItemStack> vaultItems = getItems(p, power.getTag());
for (ItemStack item : new ArrayList<>(vaultItems)) {
if (item != null && item.getType() != Material.AIR) {
if (inventoryPower.recoverable) {
p.getWorld().dropItemNaturally(p.getLocation(), item);
}
vaultItems.remove(item);
}
}

storeItems(new ArrayList<>(), p, power.getTag());
});
storeItems(new ArrayList<>(), p, power.getTag());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.dueris.calio.data.FactoryData;
import me.dueris.calio.data.factory.FactoryJsonObject;
import me.dueris.calio.data.types.OptionalInstance;
import me.dueris.calio.data.types.RequiredInstance;
import me.dueris.genesismc.GenesisMC;
import me.dueris.genesismc.factory.powers.holder.PowerType;
Expand All @@ -16,7 +17,7 @@
import org.jetbrains.annotations.NotNull;

public class ModifyFallingPower extends PowerType implements Listener {
private final float velocity;
private final Float velocity;
private final boolean takeFallDamage;

public ModifyFallingPower(String name, String description, boolean hidden, FactoryJsonObject condition, int loading_priority, float velocity, boolean takeFallDamage) {
Expand All @@ -27,7 +28,7 @@ public ModifyFallingPower(String name, String description, boolean hidden, Facto

public static FactoryData registerComponents(FactoryData data) {
return PowerType.registerComponents(data).ofNamespace(GenesisMC.apoliIdentifier("modify_falling"))
.add("velocity", float.class, new RequiredInstance())
.add("velocity", float.class, new OptionalInstance())
.add("take_fall_damage", boolean.class, true);
}

Expand All @@ -39,13 +40,15 @@ public void runE(PlayerMoveEvent e) {
@NotNull Vector velocityVal = p.getVelocity();
if (isActive(p)) {
if (velocityVal.getY() > 0D) return;
if (velocity < 0.08) {
// This way is a lot smoother and also updates the client preventing weird glitches
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 5, 1, false, false, false));
} else {
Vector veloc = e.getPlayer().getVelocity();
veloc.setY(veloc.getY() * (1 + velocity));
e.getPlayer().setVelocity(veloc);
if (velocity != null) {
if (velocity < 0.08) {
// This way is a lot smoother and also updates the client preventing weird glitches
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 5, 1, false, false, false));
} else {
Vector veloc = e.getPlayer().getVelocity();
veloc.setY(veloc.getY() * (1 + velocity));
e.getPlayer().setVelocity(veloc);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ public static void open(Player player, Layer layer, boolean inOrbChoosing) {
);

gui.setContents(layerPages.get(layer).get(currentDisplayingPage.getInt(player)).createDisplay(player, layer));
GenesisMC.getScheduler().parent.onMain(() -> {
player.getBukkitEntity().openInventory(gui);
});
player.getBukkitEntity().openInventory(gui);
}

public static void open(org.bukkit.entity.Player player, Layer layer, boolean inOrbChoosing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static boolean isInPhantomForm(Player player) {
}

public static ConcurrentLinkedQueue<PowerType> getPowersApplied(Player p) {
return powersAppliedList.get(p);
return powersAppliedList.getOrDefault(p, new ConcurrentLinkedQueue<>()); // Default returned if the player has 0 powers
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,40 @@

public class PowerUtils {
public static void removePower(CommandSender executor, PowerType poweR, Player p, Layer layer, boolean suppress) throws InstantiationException, IllegalAccessException {
GenesisMC.getScheduler().parent.offMain(() -> {
if (PowerHolderComponent.playerPowerMapping.get(p) != null) {
ArrayList<PowerType> powersToEdit = new ArrayList<>();
powersToEdit.add(poweR);
powersToEdit.addAll(CraftApoli.getNestedPowerTypes(poweR));
for (PowerType power : powersToEdit) {
try {
if (PowerHolderComponent.playerPowerMapping.get(p).get(layer).contains(power)) {
PowerHolderComponent.playerPowerMapping.get(p).get(layer).remove(power);
PowerHolderComponent.removePower(p, power, suppress, true);
if (!suppress) {
executor.sendMessage("Entity %name% had the power %power% removed"
.replace("%power%", power.getName())
.replace("%name%", p.getName())
);
}
if (PowerHolderComponent.playerPowerMapping.get(p) != null) {
ArrayList<PowerType> powersToEdit = new ArrayList<>();
powersToEdit.add(poweR);
powersToEdit.addAll(CraftApoli.getNestedPowerTypes(poweR));
for (PowerType power : powersToEdit) {
try {
if (PowerHolderComponent.playerPowerMapping.get(p).get(layer).contains(power)) {
PowerHolderComponent.playerPowerMapping.get(p).get(layer).remove(power);
PowerHolderComponent.removePower(p, power, suppress, true);
if (!suppress) {
executor.sendMessage("Entity %name% had the power %power% removed"
.replace("%power%", power.getName())
.replace("%name%", p.getName())
);
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}

// New Rewrite
public static void grantPower(CommandSender executor, PowerType power, Player p, Layer layer, boolean suppress) throws InstantiationException, IllegalAccessException {
GenesisMC.getScheduler().parent.offMain(() -> {
if (!PowerHolderComponent.playerPowerMapping.get(p).get(layer).contains(power)) {
PowerHolderComponent.playerPowerMapping.get(p).get(layer).add(power);
PowerHolderComponent.applyPower(p, power, suppress, true);
if (!suppress) {
executor.sendMessage("Entity %name% was granted the power %power%"
.replace("%power%", power.getName())
.replace("%name%", p.getName())
);
}
if (!PowerHolderComponent.playerPowerMapping.get(p).get(layer).contains(power)) {
PowerHolderComponent.playerPowerMapping.get(p).get(layer).add(power);
PowerHolderComponent.applyPower(p, power, suppress, true);
if (!suppress) {
executor.sendMessage("Entity %name% was granted the power %power%"
.replace("%power%", power.getName())
.replace("%name%", p.getName())
);
}
});
}
}
}

0 comments on commit 60077e5

Please sign in to comment.