Skip to content

Commit

Permalink
更新至1.21.1 初步适配新BS
Browse files Browse the repository at this point in the history
  • Loading branch information
LobbyTech-MC committed Nov 5, 2024
1 parent b427b72 commit 204dd8d
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 118 deletions.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<version>2.0-preview-2</version>

<properties>
<maven.compiler.source>1.17</maven.compiler.source>
<maven.compiler.target>1.17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -33,14 +33,14 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.6.0</version>
<configuration>
<relocations>
<relocation>
Expand Down Expand Up @@ -77,14 +77,14 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.Slimefun</groupId>
<groupId>com.github.SlimefunGuguProject</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-33</version>
<version>2024.3.1</version>
<scope>provided</scope>
</dependency>

Expand Down
59 changes: 35 additions & 24 deletions src/main/java/io/taraxacum/finaltech/FinalTech.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
package io.taraxacum.finaltech;

import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.taraxacum.common.util.StringNumberUtil;
import io.taraxacum.finaltech.core.patch.EnergyRegulatorBlockTicker;
import io.taraxacum.finaltech.setup.TemplateParser;
import io.taraxacum.finaltech.setup.Updater;
import io.taraxacum.finaltech.util.ConstantTableUtil;
import io.taraxacum.libs.plugin.dto.ConfigFileManager;
import io.taraxacum.libs.plugin.dto.*;
import io.taraxacum.finaltech.setup.FinalTechItemStacks;
import io.taraxacum.finaltech.setup.SetupUtil;
import io.taraxacum.libs.slimefun.dto.ItemValueTable;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.bstats.bukkit.Metrics;
import org.bstats.charts.AdvancedPie;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.taraxacum.common.util.StringNumberUtil;
import io.taraxacum.finaltech.core.patch.EnergyRegulatorBlockTicker;
import io.taraxacum.finaltech.setup.FinalTechItemStacks;
import io.taraxacum.finaltech.setup.SetupUtil;
import io.taraxacum.finaltech.setup.Updater;
import io.taraxacum.finaltech.util.ConstantTableUtil;
import io.taraxacum.libs.plugin.dto.ConfigFileManager;
import io.taraxacum.libs.plugin.dto.CustomLogger;
import io.taraxacum.libs.plugin.dto.LanguageManager;
import io.taraxacum.libs.plugin.dto.ServerRunnableLockFactory;
import io.taraxacum.libs.slimefun.dto.ItemValueTable;

/**
* @author Final_ROOT
Expand Down Expand Up @@ -315,13 +322,14 @@ public void onDisable() {
if (this.bukkitTask != null) {
this.bukkitTask.cancel();
}
BlockStorage.saveChunks();
//BlockStorage.saveChunks();
try {
FinalTech.logger().info("Waiting all task to end.(" + FinalTech.getLocationRunnableFactory().taskSize() + ")");
FinalTech.getLocationRunnableFactory().waitAllTask();
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
} finally {
}
/*finally {
BlockStorage.saveChunks();
try {
for (World world : Bukkit.getWorlds()) {
Expand All @@ -335,11 +343,13 @@ public void onDisable() {
e.printStackTrace();
}
}
*/
try {
FinalTech.getEntityRunnableFactory().waitAllTask();
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
} finally {
}
/*finally {
BlockStorage.saveChunks();
try {
for (World world : Bukkit.getWorlds()) {
Expand All @@ -353,6 +363,7 @@ public void onDisable() {
e.printStackTrace();
}
}
*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* @since 1.0
*/
public class NullEnchantment extends Enchantment {
public static final Enchantment ENCHANTMENT = new NullEnchantment(new NamespacedKey(JavaPlugin.getPlugin(FinalTech.class), "FINALTECH_NULL_ENCHANTMENT"));
public static final NamespacedKey KEY = new NamespacedKey(JavaPlugin.getPlugin(FinalTech.class), "FINALTECH_NULL_ENCHANTMENT");
public static final Enchantment ENCHANTMENT = new NullEnchantment(KEY);

private NullEnchantment(NamespacedKey key) {
super(key);
super();
}

@Nonnull
Expand Down Expand Up @@ -68,4 +69,14 @@ public static void addAndHidden(@Nonnull ItemStack item) {
item.addUnsafeEnchantment(ENCHANTMENT, 0);
ItemStackUtil.addItemFlag(item, ItemFlag.HIDE_ENCHANTS);
}

@Override
public NamespacedKey getKey() {
return KEY;
}

@Override
public String getTranslationKey() {
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import io.taraxacum.libs.slimefun.dto.BlockStorageLoreHelper;
import io.taraxacum.finaltech.core.item.machine.AbstractMachine;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -69,7 +71,8 @@ public String previousOrDefaultValue(@Nullable String value) {
public ChestMenu.MenuClickHandler getHandler(@Nonnull Inventory inventory, @Nonnull Location location, @Nonnull SlimefunItem slimefunItem, int slot) {
if (slimefunItem instanceof AbstractMachine) {
return (player, i, itemStack, clickAction) -> {
int quantity = Integer.parseInt(BlockStorage.getLocationInfo(location, MachineMaxStack.KEY));
SlimefunBlockData blockData = StorageCacheUtils.getBlock(location);
int quantity = Integer.parseInt(blockData.getData(MachineMaxStack.KEY));
if (clickAction.isShiftClicked()) {
quantity = 0;
} else {
Expand All @@ -80,7 +83,7 @@ public ChestMenu.MenuClickHandler getHandler(@Nonnull Inventory inventory, @Nonn
}
}
MachineMaxStack.HELPER.setIcon(inventory.getItem(slot), String.valueOf(quantity));
BlockStorage.addBlockInfo(location, MachineMaxStack.KEY, String.valueOf(quantity));
blockData.setData(MachineMaxStack.KEY, String.valueOf(quantity));
return false;
};
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import io.taraxacum.libs.slimefun.dto.MachineRecipeFactory;
import io.taraxacum.libs.plugin.util.ItemStackUtil;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
Expand Down Expand Up @@ -62,7 +63,7 @@ public ChestMenu.MenuClickHandler getHandler(@Nonnull Inventory inventory, @Nonn
HELPER.checkOrSetBlockStorage(location);
String value = clickAction.isRightClicked() ? VALUE_LOCK_OFF : VALUE_UNLOCK;
HELPER.setIcon(inventory.getItem(slot), value);
BlockStorage.addBlockInfo(location, KEY, value);
StorageCacheUtils.setData(location, KEY, value);
return false;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import io.taraxacum.libs.slimefun.dto.BlockStorageLoreHelper;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
Expand Down Expand Up @@ -128,7 +129,7 @@ public static abstract class BlockStorageLoreMaterialHelper extends BlockStorage
@Nonnull
@Override
public String getOrDefaultValue(@Nonnull Location location) {
String valueMap = BlockStorage.getLocationInfo(location, this.getKey());
String valueMap = StorageCacheUtils.getData(location, this.getKey());
KeyValueStringHelper keyValueStringHelper = MAP_EXAMPLE.parseString(valueMap);
String value = keyValueStringHelper.getValue(BlockStorageLoreMaterialHelper.this.getValueKey());
if ("".equals(value)) {
Expand Down Expand Up @@ -171,7 +172,7 @@ public boolean setIcon(@Nonnull ItemStack iconItem, @Nullable String value, @Non

@Override
public boolean checkAndUpdateIcon(@Nonnull Inventory inventory, @Nonnull Location location, int slot) {
String valueMap = BlockStorage.getLocationInfo(location, this.getKey());
String valueMap = StorageCacheUtils.getData(location, this.getKey());
if (valueMap == null) {
valueMap = "";
}
Expand All @@ -183,7 +184,7 @@ public boolean checkAndUpdateIcon(@Nonnull Inventory inventory, @Nonnull Locatio
if (!BlockStorageLoreMaterialHelper.this.validValue(value)) {
value = BlockStorageLoreMaterialHelper.this.defaultValue();
keyValueStringHelper.putEntry(BlockStorageLoreMaterialHelper.this.getValueKey(), value);
BlockStorage.addBlockInfo(location, KEY, keyValueStringHelper.toString());
StorageCacheUtils.setData(location, KEY, keyValueStringHelper.toString());
}
ItemStack item = inventory.getItem(slot);
item.setAmount(keyValueStringHelper.getKeyIndex(this.getValueKey()) > 0 ? keyValueStringHelper.getKeyIndex(this.getValueKey()) + 1 : 1);
Expand All @@ -195,7 +196,7 @@ public boolean checkAndUpdateIcon(@Nonnull Inventory inventory, @Nonnull Locatio
@Override
public ChestMenu.MenuClickHandler getHandler(@Nonnull Inventory inventory, @Nonnull Location location, @Nonnull SlimefunItem slimefunItem, int slot) {
return (p, slot1, item, action) -> {
String valueMap = BlockStorage.getLocationInfo(location, this.getKey());
String valueMap = StorageCacheUtils.getData(location, this.getKey());
KeyValueStringHelper keyValueStringHelper = MAP_EXAMPLE.parseString(valueMap);
String value = keyValueStringHelper.getValue(BlockStorageLoreMaterialHelper.this.getValueKey());
if ("".equals(value)) {
Expand All @@ -218,7 +219,7 @@ public ChestMenu.MenuClickHandler getHandler(@Nonnull Inventory inventory, @Nonn
@Override
public ChestMenu.MenuClickHandler getUpdateHandler(@Nonnull Inventory inventory, @Nonnull Location location, @Nonnull SlimefunItem slimefunItem, int slot) {
return (p, slot1, item, action) -> {
String valueMap = BlockStorage.getLocationInfo(location, this.getKey());
String valueMap = StorageCacheUtils.getData(location, this.getKey());
KeyValueStringHelper keyValueStringHelper = MAP_EXAMPLE.parseString(valueMap);
String value = keyValueStringHelper.getValue(BlockStorageLoreMaterialHelper.this.getValueKey());
if ("".equals(value)) {
Expand All @@ -239,7 +240,7 @@ public ChestMenu.MenuClickHandler getUpdateHandler(@Nonnull Inventory inventory,
@Override
public ChestMenu.MenuClickHandler getNextHandler(@Nonnull Inventory inventory, @Nonnull Location location, @Nonnull SlimefunItem slimefunItem, int slot) {
return (p, slot1, item, action) -> {
String valueMap = BlockStorage.getLocationInfo(location, this.getKey());
String valueMap = StorageCacheUtils.getData(location, this.getKey());
KeyValueStringHelper keyValueStringHelper = MAP_EXAMPLE.parseString(valueMap);
String value = keyValueStringHelper.getValue(BlockStorageLoreMaterialHelper.this.getValueKey());
if ("".equals(value)) {
Expand All @@ -258,7 +259,7 @@ public ChestMenu.MenuClickHandler getNextHandler(@Nonnull Inventory inventory, @
@Override
public ChestMenu.MenuClickHandler getPreviousHandler(@Nonnull Inventory inventory, @Nonnull Location location, @Nonnull SlimefunItem slimefunItem, int slot) {
return (p, slot1, item, action) -> {
String valueMap = BlockStorage.getLocationInfo(location, this.getKey());
String valueMap = StorageCacheUtils.getData(location, this.getKey());
KeyValueStringHelper keyValueStringHelper = MAP_EXAMPLE.parseString(valueMap);
String value = keyValueStringHelper.getValue(BlockStorageLoreMaterialHelper.this.getValueKey());
if ("".equals(value)) {
Expand Down
Loading

0 comments on commit 204dd8d

Please sign in to comment.