mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Progress.
This commit is contained in:
@ -19,6 +19,7 @@ import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListene
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.titles.DefaultTitle_111;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitBlockRegistry;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChatManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChunkManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitCommand;
|
||||
@ -51,6 +52,7 @@ import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridGen;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||
@ -98,6 +100,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@ -112,7 +115,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<Material> {
|
||||
|
||||
@Getter private static WorldEdit worldEdit;
|
||||
private static Map<String, Plugin> pluginMap;
|
||||
@ -168,6 +171,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
@Getter private SingleWorldListener singleWorldListener;
|
||||
private Method methodUnloadChunk0;
|
||||
private boolean methodUnloadSetup = false;
|
||||
private final BlockRegistry<Material> blockRegistry = new BukkitBlockRegistry(Material.values());
|
||||
|
||||
@Override public int[] getServerVersion() {
|
||||
if (this.version == null) {
|
||||
@ -920,4 +924,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRegistry<Material> getBlockRegistry() {
|
||||
return this.blockRegistry;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class BukkitBlockRegistry extends BlockRegistry<Material> {
|
||||
|
||||
public BukkitBlockRegistry(final Material... preInitializedItems) {
|
||||
super(Material.class, preInitializedItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock getPlotBlock(@NonNull final Material item) {
|
||||
return PlotBlock.get(item.name());
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,15 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import lombok.*;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* Borrowed from https://github.com/Phoenix616/IDConverter/blob/master/mappings/src/main/java/de/themoep/idconverter/IdMappings.java
|
||||
@ -849,6 +853,51 @@ public class LegacyMappings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to find a legacy plot block by any means possible.
|
||||
* Strategy:
|
||||
* - Check if the name contains a namespace, if so, strip it
|
||||
* - Check if there's a (new) material matching the name
|
||||
* - Check if there's a legacy material matching the name
|
||||
* - Check if there's a numerical ID matching the name
|
||||
* - Return null if everything else fails
|
||||
*
|
||||
* @param string String ID
|
||||
* @return LegacyBlock if found, else null
|
||||
*/
|
||||
public static LegacyBlock fromAny(@NonNull final String string) {
|
||||
String workingString = string;
|
||||
String[] parts = null;
|
||||
if (string.contains(":")) {
|
||||
parts = string.split(":");
|
||||
if (parts.length > 1) {
|
||||
if (parts[0].equalsIgnoreCase("minecraft")) {
|
||||
workingString = parts[1];
|
||||
} else {
|
||||
workingString = parts[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
LegacyBlock plotBlock = fromNewName(workingString);
|
||||
if (plotBlock != null) {
|
||||
return plotBlock;
|
||||
} else if ((plotBlock = fromLegacyName(workingString)) != null) {
|
||||
return plotBlock;
|
||||
} else {
|
||||
try {
|
||||
if (parts != null && parts.length > 1) {
|
||||
final int id = Integer.parseInt(parts[0]);
|
||||
final int data = Integer.parseInt(parts[1]);
|
||||
return fromIdAndData(id, data);
|
||||
} else {
|
||||
return fromLegacyId(Integer.parseInt(workingString));
|
||||
}
|
||||
} catch (final Throwable exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static LegacyBlock fromLegacyId(final int id) {
|
||||
return NUMERICAL_MAP.get(id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user