1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Remove as much old stuff as possible

This commit is contained in:
TheBusyBiscuit 2021-01-13 11:58:54 +01:00
parent f602c6c575
commit 69df04f128
4 changed files with 18 additions and 312 deletions

View File

@ -2,22 +2,10 @@ package me.mrCookieSlime.CSCoreLibPlugin.Configuration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
/** /**
* An old remnant of CS-CoreLib. * An old remnant of CS-CoreLib.
@ -30,18 +18,6 @@ public class Config {
private final File file; private final File file;
private FileConfiguration config; private FileConfiguration config;
/**
* Creates a new Config Object for the config.yml File of
* the specified Plugin
*
* @param plugin
* The Instance of the Plugin, the config.yml is referring to
*/
public Config(Plugin plugin) {
this.file = new File("plugins/" + plugin.getDescription().getName().replace(" ", "_") + "/config.yml");
this.config = YamlConfiguration.loadConfiguration(this.file);
}
/** /**
* Creates a new Config Object for the specified File * Creates a new Config Object for the specified File
* *
@ -49,8 +25,7 @@ public class Config {
* The File for which the Config object is created for * The File for which the Config object is created for
*/ */
public Config(File file) { public Config(File file) {
this.file = file; this(file, YamlConfiguration.loadConfiguration(file));
this.config = YamlConfiguration.loadConfiguration(this.file);
} }
/** /**
@ -96,10 +71,6 @@ public class Config {
return this.config; return this.config;
} }
protected void store(String path, Object value) {
this.config.set(path, value);
}
/** /**
* Sets the Value for the specified Path * Sets the Value for the specified Path
* *
@ -109,38 +80,7 @@ public class Config {
* The Value for that Path * The Value for that Path
*/ */
public void setValue(String path, Object value) { public void setValue(String path, Object value) {
if (value == null) { this.config.set(path, value);
this.store(path, value);
this.store(path + "_extra", null);
} else if (value instanceof Inventory) {
for (int i = 0; i < ((Inventory) value).getSize(); i++) {
setValue(path + "." + i, ((Inventory) value).getItem(i));
}
} else if (value instanceof Date) {
this.store(path, String.valueOf(((Date) value).getTime()));
} else if (value instanceof Long) {
this.store(path, String.valueOf(value));
} else if (value instanceof UUID) {
this.store(path, value.toString());
} else if (value instanceof Sound) {
this.store(path, String.valueOf(value));
} else if (value instanceof ItemStack) {
this.store(path, new ItemStack((ItemStack) value));
} else if (value instanceof Location) {
setValue(path + ".x", ((Location) value).getX());
setValue(path + ".y", ((Location) value).getY());
setValue(path + ".z", ((Location) value).getZ());
setValue(path + ".pitch", ((Location) value).getPitch());
setValue(path + ".yaw", ((Location) value).getYaw());
setValue(path + ".world", ((Location) value).getWorld().getName());
} else if (value instanceof Chunk) {
setValue(path + ".x", ((Chunk) value).getX());
setValue(path + ".z", ((Chunk) value).getZ());
setValue(path + ".world", ((Chunk) value).getWorld().getName());
} else if (value instanceof World) {
this.store(path, ((World) value).getName());
} else
this.store(path, value);
} }
/** /**
@ -174,9 +114,10 @@ public class Config {
* The Value for that Path * The Value for that Path
*/ */
public void setDefaultValue(String path, Object value) { public void setDefaultValue(String path, Object value) {
if (!contains(path)) if (!contains(path)) {
setValue(path, value); setValue(path, value);
} }
}
/** /**
* Checks whether the Config contains the specified Path * Checks whether the Config contains the specified Path
@ -200,17 +141,6 @@ public class Config {
return config.get(path); return config.get(path);
} }
/**
* Returns the ItemStack at the specified Path
*
* @param path
* The path in the Config File
* @return The ItemStack at that Path
*/
public ItemStack getItem(String path) {
return config.getItemStack(path);
}
/** /**
* Returns the String at the specified Path * Returns the String at the specified Path
* *
@ -222,66 +152,6 @@ public class Config {
return config.getString(path); return config.getString(path);
} }
/**
* Returns the Integer at the specified Path
*
* @param path
* The path in the Config File
* @return The Integer at that Path
*/
public int getInt(String path) {
return config.getInt(path);
}
/**
* Returns the Boolean at the specified Path
*
* @param path
* The path in the Config File
* @return The Boolean at that Path
*/
public boolean getBoolean(String path) {
return config.getBoolean(path);
}
/**
* Returns the StringList at the specified Path
*
* @param path
* The path in the Config File
* @return The StringList at that Path
*/
public List<String> getStringList(String path) {
return config.getStringList(path);
}
/**
* Returns the ItemList at the specified Path
*
* @param path
* The path in the Config File
* @return The ItemList at that Path
*/
public List<ItemStack> getItemList(String path) {
List<ItemStack> list = new ArrayList<ItemStack>();
for (String key : getKeys(path)) {
if (!key.endsWith("_extra"))
list.add(getItem(path + "." + key));
}
return list;
}
/**
* Returns the IntegerList at the specified Path
*
* @param path
* The path in the Config File
* @return The IntegerList at that Path
*/
public List<Integer> getIntList(String path) {
return config.getIntegerList(path);
}
/** /**
* Recreates the File of this Config * Recreates the File of this Config
*/ */
@ -291,143 +161,6 @@ public class Config {
} catch (IOException e) {} } catch (IOException e) {}
} }
/**
* Returns the Float at the specified Path
*
* @param path
* The path in the Config File
* @return The Float at that Path
*/
public Float getFloat(String path) {
return Float.valueOf(String.valueOf(getValue(path)));
}
/**
* Returns the Long at the specified Path
*
* @param path
* The path in the Config File
* @return The Long at that Path
*/
public Long getLong(String path) {
return Long.valueOf(String.valueOf(getValue(path)));
}
/**
* Returns the Sound at the specified Path
*
* @param path
* The path in the Config File
* @return The Sound at that Path
*/
public Sound getSound(String path) {
return Sound.valueOf(getString(path));
}
/**
* Returns the Date at the specified Path
*
* @param path
* The path in the Config File
* @return The Date at that Path
*/
public Date getDate(String path) {
return new Date(getLong(path));
}
/**
* Returns the Chunk at the specified Path
*
* @param path
* The path in the Config File
* @return The Chunk at that Path
*/
public Chunk getChunk(String path) {
return Bukkit.getWorld(getString(path + ".world")).getChunkAt(getInt(path + ".x"), getInt(path + ".z"));
}
/**
* Returns the UUID at the specified Path
*
* @param path
* The path in the Config File
* @return The UUID at that Path
*/
public UUID getUUID(String path) {
return UUID.fromString(getString(path));
}
/**
* Returns the World at the specified Path
*
* @param path
* The path in the Config File
* @return The World at that Path
*/
public World getWorld(String path) {
return Bukkit.getWorld(getString(path));
}
/**
* Returns the Double at the specified Path
*
* @param path
* The path in the Config File
* @return The Double at that Path
*/
public Double getDouble(String path) {
return config.getDouble(path);
}
/**
* Returns the Location at the specified Path
*
* @param path
* The path in the Config File
* @return The Location at that Path
*/
public Location getLocation(String path) {
if (this.contains(path + ".pitch")) {
return new Location(Bukkit.getWorld(getString(path + ".world")), getDouble(path + ".x"), getDouble(path + ".y"), getDouble(path + ".z"), getFloat(path + ".yaw"), getFloat(path + ".pitch"));
} else {
return new Location(Bukkit.getWorld(this.getString(path + ".world")), this.getDouble(path + ".x"), this.getDouble(path + ".y"), this.getDouble(path + ".z"));
}
}
@Deprecated
public void setLocation(String path, Location location) {
setValue(path + ".x", location.getX());
setValue(path + ".y", location.getY());
setValue(path + ".z", location.getZ());
setValue(path + ".world", location.getWorld().getName());
}
@Deprecated
public void setInventory(String path, Inventory inventory) {
for (int i = 0; i < inventory.getSize(); i++) {
setValue(path + "." + i, inventory.getItem(i));
}
}
/**
* Gets the Contents of an Inventory at the specified Path
*
* @param path
* The path in the Config File
* @param size
* The Size of the Inventory
* @param title
* The Title of the Inventory
* @return The generated Inventory
*/
public Inventory getInventory(String path, int size, String title) {
Inventory inventory = Bukkit.createInventory(null, size, title);
for (int i = 0; i < size; i++) {
inventory.setItem(i, getItem(path + "." + i));
}
return inventory;
}
/** /**
* Returns all Paths in this Config * Returns all Paths in this Config
* *

View File

@ -33,11 +33,10 @@ public class MenuListener implements Listener {
@EventHandler @EventHandler
public void onClose(InventoryCloseEvent e) { public void onClose(InventoryCloseEvent e) {
ChestMenu menu = menus.get(e.getPlayer().getUniqueId()); ChestMenu menu = menus.remove(e.getPlayer().getUniqueId());
if (menu != null) { if (menu != null) {
menu.getMenuCloseHandler().onClose((Player) e.getPlayer()); menu.getMenuCloseHandler().onClose((Player) e.getPlayer());
menus.remove(e.getPlayer().getUniqueId());
} }
} }

View File

@ -2,10 +2,11 @@ package me.mrCookieSlime.Slimefun.api;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.Nonnull;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -39,12 +40,13 @@ public class BlockInfoConfig extends Config {
this.data = data; this.data = data;
} }
@Nonnull
public Map<String, String> getMap() { public Map<String, String> getMap() {
return data; return data;
} }
@Override @Override
protected void store(String path, Object value) { public void setValue(String path, Object value) {
if (value != null && !(value instanceof String)) { if (value != null && !(value instanceof String)) {
throw new UnsupportedOperationException("Can't set \"" + path + "\" to \"" + value + "\" (type: " + value.getClass().getSimpleName() + ") because BlockInfoConfig only supports Strings"); throw new UnsupportedOperationException("Can't set \"" + path + "\" to \"" + value + "\" (type: " + value.getClass().getSimpleName() + ") because BlockInfoConfig only supports Strings");
} }
@ -76,70 +78,42 @@ public class BlockInfoConfig extends Config {
return data.keySet(); return data.keySet();
} }
@Override
public int getInt(String path) {
throw invalidType(path);
}
@Override
public boolean getBoolean(String path) {
throw invalidType(path);
}
@Override
public List<String> getStringList(String path) {
throw invalidType(path);
}
@Override
public List<Integer> getIntList(String path) {
throw invalidType(path);
}
@Override
public Double getDouble(String path) {
throw invalidType(path);
}
@Override @Override
public Set<String> getKeys(String path) { public Set<String> getKeys(String path) {
throw invalidType(path); throw new UnsupportedOperationException("Cannot get keys for BlockInfoConfig");
}
private UnsupportedOperationException invalidType(String path) {
return new UnsupportedOperationException("Can't get \"" + path + "\" because BlockInfoConfig only supports String values");
} }
@Override @Override
public File getFile() { public File getFile() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException("BlockInfoConfigs do not have a File");
} }
@Override @Override
public FileConfiguration getConfiguration() { public FileConfiguration getConfiguration() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException("BlockInfoConfigs do not have a FileConfiguration");
} }
@Override @Override
public void save() { public void save() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException("BlockInfoConfigs cannot be saved to a File");
} }
@Override @Override
public void save(File file) { public void save(File file) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException("BlockInfoConfigs cannot be saved to a File");
} }
@Override @Override
public void createFile() { public void createFile() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException("BlockInfoConfigs cannot be created from a File");
} }
@Override @Override
public void reload() { public void reload() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException("BlockInfoConfigs cannot be reloaded");
} }
@Nonnull
public String toJSON() { public String toJSON() {
return new GsonBuilder().create().toJson(data); return new GsonBuilder().create().toJson(data);
} }

View File

@ -17,7 +17,7 @@ class EmptyBlockData extends BlockInfoConfig {
} }
@Override @Override
protected void store(String path, Object value) { public void setValue(String path, Object value) {
throw new UnsupportedOperationException("Cannot store values (" + path + ':' + value + " on a read-only data object!"); throw new UnsupportedOperationException("Cannot store values (" + path + ':' + value + " on a read-only data object!");
} }