Skip to content

Commit

Permalink
Fixes galore
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed May 24, 2024
1 parent bbad228 commit 321e2dd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.dueris.genesismc.factory.data.types;

import com.google.common.base.Preconditions;
import me.dueris.calio.data.factory.FactoryJsonArray;
import me.dueris.calio.data.factory.FactoryJsonObject;
import me.dueris.genesismc.util.Util;
Expand All @@ -15,6 +16,7 @@ public class Modifier {

public Modifier(FactoryJsonObject factoryJsonObject) {
this.handle = factoryJsonObject;
Preconditions.checkArgument(handle.isPresent("value"), "Value must be present!");
}

public static Modifier[] getModifiers(@Nullable FactoryJsonObject singular, @Nullable FactoryJsonArray plural) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public class ClimbingPower extends PowerType {
public static ArrayList<Player> active_climbing = new ArrayList<>();
private final boolean allowHolding;
public ArrayList<Player> holdingPlayers = new ArrayList<>();
public ArrayList<Player> allowedToClimb = new ArrayList<>();

public ClimbingPower(String name, String description, boolean hidden, FactoryJsonObject condition, int loading_priority, boolean allowHolding) {
Expand All @@ -37,24 +36,13 @@ public static boolean isActiveClimbing(Player player) {
return active_climbing.contains(player);
}

public static ArrayList<Player> getActiveClimbingMap() {
return active_climbing;
}

@Override
public void tick(Player p) {
if (!p.isSneaking()) holdingPlayers.remove(p);
if (!((CraftWorld) p.getWorld()).getHandle().getBlockStates(((CraftPlayer) p).getHandle().getBoundingBox().inflate(0.1, 0, 0.1)).filter(state -> state.getBukkitMaterial().isCollidable()).toList().isEmpty()) {
if (isActive(p) && allowedToClimb.contains(p)) {
active_climbing.add(p);
p.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 4, 2, false, false, false));
getActiveClimbingMap().add(p);
new BukkitRunnable() {
@Override
public void run() {
getActiveClimbingMap().remove(p);
}
}.runTaskLater(GenesisMC.getPlugin(), 2L);
}
} else active_climbing.remove(p);
}
}

Expand All @@ -75,36 +63,6 @@ public void run() {
}
}

@EventHandler
public void latch(PlayerToggleSneakEvent e) {
Player p = e.getPlayer();
if (getPlayers().contains(p)) {
if (this.isAllowHolding()) {
final Location[] location = {p.getLocation()};
if (e.isSneaking() && getActiveClimbingMap().contains(p)) {
new BukkitRunnable() {
@Override
public void run() {
if (p.isSneaking()) {
if (location[0].getPitch() != p.getPitch() || location[0].getYaw() != p.getYaw()) {
float pitch = p.getPitch();
float yaw = p.getYaw();
Location updatedLocation = new Location(location[0].getWorld(), location[0].getX(), location[0].getY(), location[0].getZ(), yaw, pitch);
location[0] = updatedLocation;
}
p.teleportAsync(location[0]);
holdingPlayers.add(p);
} else {
holdingPlayers.remove(p);
cancel();
}
}
}.runTaskTimer(GenesisMC.getPlugin(), 0, 1);
}
}
}
}

public boolean isAllowHolding() {
return allowHolding;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.craftbukkit.util.CraftLocation;
Expand Down Expand Up @@ -47,7 +48,8 @@ public void tick(Player p) {
continue;
}
if (useTeams() && player.getTeam() != null) {
utils.setGlowing(entity.getBukkitEntity(), p, CraftChatMessage.getColor(player.getTeam().getColor()));
ChatColor color = CraftChatMessage.getColor(player.getTeam().getColor());
utils.setGlowing(entity.getBukkitEntity(), p, (color == null || color.toString().equalsIgnoreCase("§r")) ? ChatColor.WHITE : color);
} else {
Color awtColor = new Color(getRed(), getGreen(), getBlue());
utils.setGlowing(entity.getBukkitEntity(), p, translateBarColor(TextureLocation.convertToBarColor(awtColor)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void parseRecipes() {
FactoryJsonObject recipe = recipePower.getRecipe();
if (recipe == null)
throw new IllegalArgumentException("Unable to find recipe data for power: " + recipePower.getTag());
NamespacedKey key = new NamespacedKey(recipe.getString("id").split(":")[0], recipe.getString("id").split(":")[1]);
NamespacedKey key = recipe.getString("id").contains(":") ? recipe.getNamespacedKey("id") : NamespacedKey.fromString(recipePower.getTag() + "_" + recipe.getString("id"));
String type = recipe.getString("type");
if (!type.startsWith("minecraft:")) {
type = "minecraft:" + type;
Expand Down Expand Up @@ -126,12 +126,13 @@ public void applyRecipePower(Player p) {
if (getPlayers().contains(p)) {
for (RecipePower power : PowerHolderComponent.getPowers(p, RecipePower.class)) {
FactoryJsonObject recipe = power.getRecipe();
String id = recipe.getString("id");
NamespacedKey idKey = recipe.getString("id").contains(":") ? recipe.getNamespacedKey("id") : NamespacedKey.fromString(power.getTag() + "_" + recipe.getString("id"));
String id = idKey.asString();
if (taggedRegistry.containsKey(id)) {
if (recipeMapping.containsKey(p)) {
recipeMapping.get(p).add(id);
} else {
recipeMapping.put(p, List.of(id));
recipeMapping.put(p, new ArrayList<>(List.of(id)));
}
} else {
throw new IllegalStateException("Unable to locate recipe id. Bug?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public static ChatColor translateBarColor(BarColor barColor) {
case PINK -> ChatColor.LIGHT_PURPLE;
case PURPLE -> ChatColor.DARK_PURPLE;
case RED -> ChatColor.RED;
case WHITE -> ChatColor.WHITE;
case YELLOW -> ChatColor.YELLOW;
default -> ChatColor.WHITE;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public ItemStack[] createDisplay(Player player, Layer layer) {

@Override
public ItemStack getChoosingStack(Player player) {
if (OrbOfOrigins.orb == null) OrbOfOrigins.init();
ItemStack orb = OrbOfOrigins.orb;
ItemMeta meta = orb.getItemMeta();
meta.displayName(Component.text("Random Origin").color(TextColor.color(0x28A7B5)));
Expand Down

0 comments on commit 321e2dd

Please sign in to comment.