Refactored some old code

This commit is contained in:
Daniel 2019-04-30 00:39:13 +02:00
parent 74c346924b
commit 15b5f79acf
38 changed files with 57 additions and 48 deletions

View File

@ -15,7 +15,7 @@ public abstract class OrcInventory {
private int rows;
private InventoryType type;
protected HashMap<Integer, OrcItem> items = new HashMap<>();
protected final HashMap<Integer, OrcItem> items = new HashMap<>();
public OrcInventory(String title) {
Objects.requireNonNull(title, "title cannot be null");

View File

@ -15,7 +15,12 @@ import de.butzlabben.world.wrapper.WorldPlayer;
public class OrcItem {
public static OrcItem enabled, disabled, coming_soon, back, fill, error = new OrcItem(Material.BARRIER, null,
public static OrcItem enabled;
public static OrcItem disabled;
public static OrcItem coming_soon;
public static OrcItem back;
public static OrcItem fill;
public static final OrcItem error = new OrcItem(Material.BARRIER, null,
"§cERROR: Item is wrong configured!", "§cPath in config: see Displayname");
private ItemStack is;

View File

@ -20,7 +20,7 @@ public class OrcListener implements Listener {
private static OrcListener instance;
private HashMap<UUID, OrcInventory> invs = new HashMap<>();
private final HashMap<UUID, OrcInventory> invs = new HashMap<>();
public static synchronized OrcListener getInstance() {
if (instance == null)

View File

@ -34,11 +34,11 @@ import com.mojang.util.UUIDTypeAdapter;
*/
public class GameProfileBuilder {
private static Gson gson = new GsonBuilder().disableHtmlEscaping()
private static final Gson gson = new GsonBuilder().disableHtmlEscaping()
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
.registerTypeAdapter(GameProfile.class, new GameProfileSerializer())
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
private static HashMap<UUID, CachedProfile> cache = new HashMap<>();
private static final HashMap<UUID, CachedProfile> cache = new HashMap<>();
private static long cacheTime = -1L;
private static final Object sync = new Object();
@ -133,7 +133,7 @@ public class GameProfileBuilder {
}
private static class CachedProfile {
private GameProfile profile;
private final GameProfile profile;
public CachedProfile(GameProfile profile) {
this.profile = profile;

View File

@ -145,7 +145,7 @@ public class WorldSystem extends JavaPlugin {
if (!dir.exists()) {
dir.mkdirs();
}
if (languages.exists() == false)
if (!languages.exists())
languages.mkdirs();
PluginConfig.checkConfig(config);

View File

@ -13,8 +13,8 @@ import java.nio.channels.ReadableByteChannel;
*/
public class AutoUpdate implements Runnable {
private UpdateInformations ui;
private String jar;
private final UpdateInformations ui;
private final String jar;
protected AutoUpdate(UpdateInformations ui, String jar) {
this.ui = ui;

View File

@ -58,7 +58,7 @@ public class AutoUpdater implements Listener {
+ ", Available: " + ui.getVersion());
}
// Get jar file
Method getFileMethod = null;
Method getFileMethod;
try {
getFileMethod = JavaPlugin.class.getDeclaredMethod("getFile");
} catch (NoSuchMethodException | SecurityException e1) {
@ -66,7 +66,7 @@ public class AutoUpdater implements Listener {
return;
}
getFileMethod.setAccessible(true);
File file = null;
File file;
try {
file = (File) getFileMethod.invoke(plugin);

View File

@ -27,7 +27,7 @@ public class UpdateInformations {
public static String callURL(String URL) {
StringBuilder sb = new StringBuilder();
URLConnection urlConn = null;
URLConnection urlConn;
InputStreamReader in = null;
try {
URL url = new URL(URL);

View File

@ -29,7 +29,7 @@ import java.util.ArrayList;
public class WorldSettingsCommands {
private ArrayList<Player> toConfirm = new ArrayList<>();
private final ArrayList<Player> toConfirm = new ArrayList<>();
@Command(name="ws.reset", inGameOnly = true, usage = "/ws reset [confirm]")
public void resetCommand(CommandArgs args) {

View File

@ -98,7 +98,7 @@ public class DependenceConfig {
}
public String getWorldNamebyOfflinePlayer() {
String name = "";
String name;
String uuid = op.getUniqueId().toString();
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig);

View File

@ -8,9 +8,9 @@ import org.bukkit.configuration.file.YamlConfiguration;
public class Entry {
private OfflinePlayer op;
private final OfflinePlayer op;
private int id;
private String worldname;
private final String worldname;
public static int entrys() {
int entrys = 0;

View File

@ -30,7 +30,7 @@ public class GuiConfig {
public static void checkConfig(File f) {
file = f;
if (file.exists() == false) {
if (!file.exists()) {
try {
String guiFileResource;
if (WorldSystem.is1_13()) {

View File

@ -17,7 +17,7 @@ public class MessageConfig {
private MessageConfig() {
}
private static List<String> defaultCmdHelp = new ArrayList<>(20);
private static final List<String> defaultCmdHelp = new ArrayList<>(20);
static {
defaultCmdHelp.add("/ws get §8- §7Will give you a World");
@ -40,7 +40,7 @@ public class MessageConfig {
public static void checkConfig(File f) {
file = f;
if (file.exists() == false) {
if (!file.exists()) {
try {
InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource(f.getName());

View File

@ -25,7 +25,7 @@ import de.butzlabben.world.wrapper.SystemWorld;
public class SettingsConfig {
private static HashMap<String, Long> borderSizes = new HashMap<>();
private static final HashMap<String, Long> borderSizes = new HashMap<>();
private static File file;

View File

@ -20,6 +20,7 @@ import java.util.*;
*
* @since 01.05.2018
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public class WorldConfig {
public static File getWorldFile(String worldname) {
@ -43,7 +44,7 @@ public class WorldConfig {
return getWorldFile(worldname).exists();
}
private static HashMap<String, WorldConfig> instances = new HashMap<>();
private static final HashMap<String, WorldConfig> instances = new HashMap<>();
/**
* Gets the worldconfig for a specific worldname or creates a new one of no
@ -249,7 +250,7 @@ public class WorldConfig {
* @return if the player was a member of this world
*/
public boolean removeMember(UUID player, UUID target) {
if (hasPermission(player, WorldPerm.EDITMEMBERS) && hasPermission(player, WorldPerm.EDITMEMBERS) == false) {
if (hasPermission(player, WorldPerm.EDITMEMBERS) && !hasPermission(player, WorldPerm.EDITMEMBERS)) {
return removeMember(target);
}
return false;

View File

@ -15,7 +15,7 @@ public class WorldAddmemberEvent extends WorldEvent {
private final String worldname;
private final UUID uuid;
private Player adder;
private final Player adder;
public WorldAddmemberEvent(UUID uuid, String worldname, Player adder) {
this.uuid = uuid;

View File

@ -37,7 +37,7 @@ public class WorldDeleteEvent extends WorldEvent {
public final static HandlerList handlers = new HandlerList();
public final static HandlerList getHandlerList() {
public static HandlerList getHandlerList() {
return handlers;
}

View File

@ -37,7 +37,7 @@ public class WorldLoadEvent extends WorldEvent {
public final static HandlerList handlers = new HandlerList();
public final static HandlerList getHandlerList() {
public static HandlerList getHandlerList() {
return handlers;
}

View File

@ -13,7 +13,7 @@ public class WorldRemovememberEvent extends WorldEvent {
private final String worldname;
private final UUID uuid;
private Player remover;
private final Player remover;
public WorldRemovememberEvent(UUID uuid, String worldname, Player remover) {
this.uuid = uuid;

View File

@ -39,7 +39,7 @@ public class WorldResetEvent extends WorldEvent {
public final static HandlerList handlers = new HandlerList();
public final static HandlerList getHandlerList() {
public static HandlerList getHandlerList() {
return handlers;
}

View File

@ -53,7 +53,7 @@ public class WorldToggleFireEvent extends WorldEvent {
public final static HandlerList handlers = new HandlerList();
public final static HandlerList getHandlerList() {
public static HandlerList getHandlerList() {
return handlers;
}

View File

@ -52,7 +52,7 @@ public class WorldToggleTntEvent extends WorldEvent {
public final static HandlerList handlers = new HandlerList();
public final static HandlerList getHandlerList() {
public static HandlerList getHandlerList() {
return handlers;
}

View File

@ -25,7 +25,7 @@ public class WorldUnloadEvent extends WorldEvent {
public final static HandlerList handlers = new HandlerList();
public final static HandlerList getHandlerList() {
public static HandlerList getHandlerList() {
return handlers;
}

View File

@ -12,7 +12,7 @@ public class GuiCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player == false) {
if (!(sender instanceof Player)) {
sender.sendMessage("You are not a player");
return true;
}

View File

@ -45,7 +45,7 @@ public class PlayerOptionsGUI extends OrcInventory {
}
public void loadItem(String subpath, String message, DependListener depend) {
if (GuiConfig.isEnabled(path + subpath) == false)
if (!GuiConfig.isEnabled(path + subpath))
return;
OrcItem item = GuiConfig.getItem(path + subpath);
if (item != null) {

View File

@ -63,7 +63,7 @@ public class WorldChooseGUI extends OrcInventory {
}
public void loadItem(String subpath, OrcClickListener listener) {
if (GuiConfig.isEnabled(path + subpath) == false)
if (!GuiConfig.isEnabled(path + subpath))
return;
OrcItem item = GuiConfig.getItem(path + subpath);
if (item != null) {

View File

@ -28,7 +28,7 @@ public class WorldOptionsGUI extends OrcInventory {
loadItem("fire", "/ws fire", true, new FireStatus());
loadItem("tnt", "/ws tnt", true, new TntStatus());
if (GuiConfig.isEnabled(path + "reset") == false)
if (!GuiConfig.isEnabled(path + "reset"))
return;
OrcItem item = GuiConfig.getItem(path + "reset");
@ -51,7 +51,7 @@ public class WorldOptionsGUI extends OrcInventory {
}
public void loadItem(String subpath, String message, boolean state, DependListener depend) {
if (GuiConfig.isEnabled(path + subpath) == false)
if (!GuiConfig.isEnabled(path + subpath))
return;
OrcItem item = GuiConfig.getItem(path + subpath);
if (item != null) {

View File

@ -41,7 +41,7 @@ public class WorldSystemGUI extends OrcInventory {
}
public void loadItem(String subpath, OrcClickListener listener) {
if (GuiConfig.isEnabled(path + subpath) == false)
if (!GuiConfig.isEnabled(path + subpath))
return;
OrcItem item = GuiConfig.getItem(path + subpath);
if (item != null) {

View File

@ -1,6 +1,7 @@
package de.butzlabben.world.listener;
import java.io.File;
import java.util.Objects;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -18,7 +19,7 @@ public class BlockListener implements Listener {
@EventHandler
public void onExplode(EntityExplodeEvent e) {
File file = WorldConfig.getWorldFile(e.getLocation().getWorld().getName());
File file = WorldConfig.getWorldFile(Objects.requireNonNull(e.getLocation().getWorld()).getName());
if(!file.exists())
return;
WorldConfig wc = WorldConfig.getWorldConfig(e.getLocation().getWorld().getName());

View File

@ -16,7 +16,7 @@ import de.butzlabben.world.wrapper.WorldPlayer;
public class PlayerDeathListener implements Listener {
private HashMap<UUID, World> deathLocations = new HashMap<>();
private final HashMap<UUID, World> deathLocations = new HashMap<>();
@EventHandler
public void onDie(PlayerDeathEvent e) {

View File

@ -15,7 +15,7 @@ import java.util.UUID;
* Used for #15
*/
public class MoneyUtil {
private static Object economy = null;
private static final Object economy = null;
static {
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {

View File

@ -12,7 +12,7 @@ import java.util.Objects;
public class PapiExtension extends PlaceholderExpansion {
private WorldSystem worldSystem = WorldSystem.getInstance();
private final WorldSystem worldSystem = WorldSystem.getInstance();
@Override
public String getIdentifier() {

View File

@ -24,7 +24,7 @@ public class PlayerPositions {
@Getter
private static PlayerPositions instance = new PlayerPositions();
private DatabaseUtil util = DatabaseRepository.getInstance().getUtil();
private final DatabaseUtil util = DatabaseRepository.getInstance().getUtil();
public Location injectWorldsLocation(Player player, WorldConfig config, Location location) {

View File

@ -12,7 +12,7 @@ import org.bukkit.entity.Player;
*/
public class TeleportUtil {
private static HashMap<UUID, Location> oldLocs = new HashMap<>();
private static final HashMap<UUID, Location> oldLocs = new HashMap<>();
public static void teleportPlayer(Player p, Location loc) {
// Save old player location.

View File

@ -8,6 +8,8 @@ import org.bukkit.block.Block;
import com.boydti.fawe.bukkit.wrapper.AsyncWorld;
import com.boydti.fawe.util.TaskManager;
import java.util.Objects;
/**
* @author Butzlabben
* @since 08.06.2018
@ -24,7 +26,7 @@ public class AsyncCreatorAdapter implements CreatorAdapter {
if (Bukkit.getWorld(creator.name()) == null)
world = AsyncWorld.create(creator);
else
world = AsyncWorld.wrap(Bukkit.getWorld(creator.name()));
world = AsyncWorld.wrap(Objects.requireNonNull(Bukkit.getWorld(creator.name())));
Block block = world.getBlockAt(0, 0, 0);
block.setType(Material.BEDROCK);

View File

@ -29,7 +29,7 @@ public class SystemWorld {
private boolean unloading = false;
private boolean creating = false;
private static HashMap<String, SystemWorld> cached = new HashMap<>();
private static final HashMap<String, SystemWorld> cached = new HashMap<>();
/**
* This method is the online way to get a system world instance

View File

@ -21,8 +21,8 @@ import java.io.IOException;
*/
public class WorldPlayer {
private OfflinePlayer p;
private String worldname;
private final OfflinePlayer p;
private final String worldname;
/**
* @return the worldname, where the worldplayer object was created for

View File

@ -12,13 +12,13 @@ import java.util.HashMap;
*/
public class WorldTemplateProvider {
private static WorldTemplateProvider instance = new WorldTemplateProvider();
private static final WorldTemplateProvider instance = new WorldTemplateProvider();
public static WorldTemplateProvider getInstace() {
return instance;
}
private HashMap<String, WorldTemplate> templates = new HashMap<>();
private final HashMap<String, WorldTemplate> templates = new HashMap<>();
private WorldTemplateProvider() {
ConfigurationSection section = PluginConfig.getConfig().getConfigurationSection("worldtemplates.templates");