Skip to content

Commit

Permalink
Fix for 1.16 item names
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackBeltPanda committed Aug 10, 2020
1 parent 343d585 commit f9d0cb1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import de.robotricker.transportpipes.duct.pipe.Pipe;
import de.robotricker.transportpipes.duct.types.BaseDuctType;
import de.robotricker.transportpipes.inventory.PlayerSettingsInventory;
import de.robotricker.transportpipes.items.ItemService;
import de.robotricker.transportpipes.items.PipeItemManager;
import de.robotricker.transportpipes.listener.DuctListener;
import de.robotricker.transportpipes.listener.PlayerListener;
Expand Down Expand Up @@ -58,11 +59,11 @@ public class TransportPipes extends JavaPlugin {
@Override
public void onEnable() {

if (Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16")) {
if (Bukkit.getVersion().contains("1.16")) {
LegacyUtils.setInstance(new LegacyUtils_1_15());
} else {
System.err.println("------------------------------------------");
System.err.println("TransportPipes currently only works with Minecraft 1.15 and above.");
System.err.println("TransportPipes currently only works with Minecraft 1.16 and above.");
System.err.println("------------------------------------------");
Bukkit.getPluginManager().disablePlugin(this);
return;
Expand Down Expand Up @@ -115,6 +116,8 @@ public void onEnable() {
//Initialize thread
thread = injector.getSingleton(ThreadService.class);
thread.start();

injector.getSingleton(ItemService.class);

//Register pipe
BaseDuctType<Pipe> baseDuctType = injector.getSingleton(DuctRegister.class).registerBaseDuctType("Pipe", PipeManager.class, PipeFactory.class, PipeItemManager.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.robotricker.transportpipes.inventory;

import java.util.Set;

import javax.inject.Inject;

import org.bukkit.entity.Player;
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/de/robotricker/transportpipes/items/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;

import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
Expand All @@ -44,15 +45,18 @@ public class ItemService {

private ItemStack wrench;
private YamlConfiguration tempConf;
private TransportPipes transportPipes;

@Inject
public ItemService(GeneralConf generalConf) {
public ItemService(GeneralConf generalConf, TransportPipes transportPipes) {
Material wrenchMaterial = Material.getMaterial(generalConf.getWrenchItem().toUpperCase(Locale.ENGLISH));
Objects.requireNonNull(wrenchMaterial, "The material for the wrench item set in the config file is not valid.");

wrench = generalConf.getWrenchGlowing() ? createGlowingItem(wrenchMaterial) : new ItemStack(wrenchMaterial);
wrench = changeDisplayNameAndLoreConfig(wrench, LangConf.Key.WRENCH.getLines());
tempConf = new YamlConfiguration();

this.transportPipes = transportPipes;
}

public ItemStack getWrench() {
Expand Down Expand Up @@ -203,11 +207,18 @@ public void populateInventoryLine(Inventory inv, int row, ItemStack... items) {

public ItemStack createWildcardItem(Material material) {
ItemStack glassPane = new ItemStack(material);
ItemMeta meta = glassPane.getItemMeta();
meta.getPersistentDataContainer().set(new NamespacedKey(transportPipes, "wildcard"), PersistentDataType.INTEGER, 1);
glassPane.setItemMeta(meta);
return changeDisplayNameAndLore(glassPane, ChatColor.RESET.toString());
}

public ItemStack createBarrierItem() {
return changeDisplayNameAndLore(new ItemStack(Material.BARRIER), ChatColor.RESET.toString());
ItemStack barrier = new ItemStack(Material.BARRIER);
ItemMeta meta = barrier.getItemMeta();
meta.getPersistentDataContainer().set(new NamespacedKey(transportPipes, "barrier"), PersistentDataType.INTEGER, 1);
barrier.setItemMeta(meta);
return changeDisplayNameAndLore(barrier, ChatColor.RESET.toString());
}

public boolean isItemWildcardOrBarrier(ItemStack item) {
Expand All @@ -231,7 +242,8 @@ public boolean isItemWildcardOrBarrier(ItemStack item) {
case PURPLE_STAINED_GLASS_PANE:
case BARRIER:
if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
return item.getItemMeta().getDisplayName().equals(ChatColor.RESET.toString());
return item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(transportPipes, "wildcard"), PersistentDataType.INTEGER)
|| item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(transportPipes, "barrier"), PersistentDataType.INTEGER);
}
default:
return false;
Expand Down

0 comments on commit f9d0cb1

Please sign in to comment.