Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
SpraxDev committed Oct 2, 2024
2 parents 8799a6f + e9f84d3 commit 0ce5b23
Show file tree
Hide file tree
Showing 70 changed files with 832 additions and 1,549 deletions.
2 changes: 1 addition & 1 deletion Compatibility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.craftaro</groupId>
<artifactId>CraftaroCore-Modules</artifactId>
<version>3.5.0-SNAPSHOT</version>
<version>3.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>CraftaroCore-Compatibility</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.craftaro.core.compatibility.crops;

import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XBlock;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CompatibleCrop {
private static final boolean USE_LEGACY_IMPLEMENTATION;

static {
boolean useLegacy = false;
try {
Class.forName("org.bukkit.block.data.Ageable");
} catch (ClassNotFoundException ignore) {
useLegacy = true;
}
USE_LEGACY_IMPLEMENTATION = useLegacy;
}

public static boolean isCrop(@Nullable Block block) {
if (block == null) {
return false;
}

XMaterial material = CompatibleMaterial.getMaterial(block.getType()).get();
return isCrop(material);
}

public static boolean isCrop(@Nullable XMaterial material) {
return material != null && XBlock.isCrop(material);
}

public static boolean isCropFullyGrown(@NotNull Block crop) {
return getCropAge(crop) >= getCropMaxAge(crop);
}

public static int getCropAge(@NotNull Block crop) {
if (!USE_LEGACY_IMPLEMENTATION) {
return CompatibleCropModern.getCropAge(crop);
}
return crop.getData();
}

public static int getCropMaxAge(@NotNull Block crop) {
if (!USE_LEGACY_IMPLEMENTATION) {
return CompatibleCropModern.getCropMaxAge(crop);
}

switch (CompatibleMaterial.getMaterial(crop.getType()).get()) {
case BEETROOTS:
case NETHER_WART:
return 3;
default:
return 7;
}
}

public static void resetCropAge(@NotNull Block crop) {
setCropAge(crop, 0);
}

public static void incrementCropAge(@NotNull Block crop) {
setCropAge(crop, getCropAge(crop) + 1);
}

private static void setCropAge(Block block, int stage) {
if (stage > getCropMaxAge(block)) {
return;
}

if (!USE_LEGACY_IMPLEMENTATION) {
CompatibleCropModern.setGrowthStage(block, stage);
return;
}

try {
Block.class.getDeclaredMethod("setData", byte.class).invoke(block, (byte) stage);
} catch (ReflectiveOperationException ex) {
throw new RuntimeException(ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.craftaro.core.compatibility.crops;

import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;

class CompatibleCropModern {
static int getCropAge(Block block) {
BlockData blockData = block.getBlockData();
return ((Ageable) blockData).getAge();
}

static int getCropMaxAge(Block block) {
BlockData blockData = block.getBlockData();
return ((Ageable) blockData).getMaximumAge();
}

static void setGrowthStage(Block block, int stage) {
Ageable blockData = (Ageable) block.getBlockData();
blockData.setAge(stage);
block.setBlockData(blockData);
}
}
2 changes: 1 addition & 1 deletion Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.craftaro</groupId>
<artifactId>CraftaroCore-Modules</artifactId>
<version>3.5.0-SNAPSHOT</version>
<version>3.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>CraftaroCore</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions Core/src/main/java/com/craftaro/core/chat/AdventureUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
Expand All @@ -25,12 +22,10 @@
import java.lang.reflect.Method;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class AdventureUtils {
private static Method displayNameMethod = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

Expand Down
1 change: 0 additions & 1 deletion Core/src/main/java/com/craftaro/core/gui/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity;
Expand Down
12 changes: 5 additions & 7 deletions Core/src/main/java/com/craftaro/core/locale/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
import com.craftaro.core.chat.AdventureUtils;
import com.craftaro.core.chat.MiniMessagePlaceholder;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.utils.TextUtils;
import net.kyori.adventure.Adventure;
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;

/**
* The Message object. This holds the message to be sent
Expand Down Expand Up @@ -138,8 +133,11 @@ public Component getMessage() {
* @return the message
*/
public List<Component> getMessageLines() {
//return Arrays.asList(ChatColor.translateAlternateColorCodes('&', this.message.toText()).split("[\n|]"));
return AdventureUtils.splitComponent(this.message, '\n');
return getMessageLines('\n');
}

public List<Component> getMessageLines(char splitChar) {
return AdventureUtils.splitComponent(this.message, splitChar);
}

/**
Expand Down
Loading

0 comments on commit 0ce5b23

Please sign in to comment.