Added defaults to config

This commit is contained in:
stijnb1234 2020-02-03 15:10:28 +01:00
parent 3cc819cd7d
commit 17214098cd
8 changed files with 95 additions and 40 deletions

View file

@ -96,8 +96,7 @@ public class MoveLift implements Runnable {
return;
}
//TODO Add defaults to config (chanceOfDefect)
double changeOfDefect = 0.0D;
double changeOfDefect = V10LiftPlugin.getSConfig().getFile().getDouble("DefectRate");
if (changeOfDefect > 0.0D) {
y = new Random().nextInt(100);
double chance;

View file

@ -6,6 +6,7 @@ import nl.SBDeveloper.V10Lift.API.Runnables.MoveLift;
import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager;
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
@ -83,8 +84,7 @@ public class V10LiftAPI {
Bukkit.getLogger().info("[V10Lift] Creating lift " + liftName);
if (p == null || liftName == null || DataManager.containsLift(liftName)) return false;
//TODO Add defaults to config
DataManager.addLift(liftName, new Lift(p.getUniqueId(), 16, true));
DataManager.addLift(liftName, new Lift(p.getUniqueId(), V10LiftPlugin.getSConfig().getFile().getInt("DefaultSpeed"), V10LiftPlugin.getSConfig().getFile().getBoolean("DefaultRealistic")));
return true;
}
@ -98,9 +98,31 @@ public class V10LiftAPI {
Bukkit.getLogger().info("[V10Lift] Removing lift " + liftName);
if (liftName == null || !DataManager.containsLift(liftName)) return false;
//TODO Remove lift from all data maps
Iterator<Map.Entry<UUID, String>> iter = DataManager.getEditors().entrySet().iterator();
HashSet<UUID> activeEdits = new HashSet<>();
while (iter.hasNext()) {
Map.Entry<UUID, String> entry = iter.next();
if (entry.getValue().equals(liftName)) {
activeEdits.add(entry.getKey());
iter.remove();
}
}
//TODO Stop movingtask if running
for (UUID puuid : activeEdits) {
DataManager.removeInputEditsPlayer(puuid);
DataManager.removeInputRemovesPlayer(puuid);
DataManager.removeOfflineEditsPlayer(puuid);
DataManager.removeOfflineRemovesPlayer(puuid);
DataManager.removeBuilderPlayer(puuid);
DataManager.removeRopeEditPlayer(puuid);
DataManager.removeRopeRemovesPlayer(puuid);
DataManager.removeDoorEditPlayer(puuid);
}
if (DataManager.containsMovingTask(liftName)) {
Bukkit.getScheduler().cancelTask(DataManager.getMovingTask(liftName));
DataManager.removeMovingTask(liftName);
}
DataManager.removeLift(liftName);
return true;
@ -336,8 +358,8 @@ public class V10LiftAPI {
if (lift.isRealistic()) {
lift.setDoorCloser(new DoorCloser(liftName));
//TODO Add defaults (doorclosetime) to config
long doorCloseTime = 5 * 20;
long doorCloseTime = V10LiftPlugin.getSConfig().getFile().getLong("DoorCloseTime");
int pid = Bukkit.getScheduler().scheduleSyncRepeatingTask(V10LiftPlugin.getInstance(), lift.getDoorCloser(), doorCloseTime, doorCloseTime);
lift.getDoorCloser().setPid(pid);
}
@ -366,8 +388,8 @@ public class V10LiftAPI {
if (lift.isRealistic()) {
lift.setDoorCloser(new DoorCloser(liftName));
//TODO Add defaults (doorclosetime) to config
long doorCloseTime = 5 * 20;
long doorCloseTime = V10LiftPlugin.getSConfig().getFile().getLong("DoorCloseTime");
int pid = Bukkit.getScheduler().scheduleSyncRepeatingTask(V10LiftPlugin.getInstance(), lift.getDoorCloser(), doorCloseTime, doorCloseTime);
lift.getDoorCloser().setPid(pid);
}
@ -560,8 +582,7 @@ public class V10LiftAPI {
Sign s = (Sign) bs;
ls.setOldText(s.getLine(3));
//TODO Add defaults to config
s.setLine(3, ChatColor.MAGIC + "Defect!");
s.setLine(3, ConfigUtil.getColored("DefectText"));
s.update();
//Update all other signs
@ -571,7 +592,7 @@ public class V10LiftAPI {
s = (Sign) bs;
lift.setSignText(s.getLine(3));
s.setLine(3, ChatColor.MAGIC + "Defect!");
s.setLine(3, ConfigUtil.getColored("DefectText"));
s.update();
}
} else {
@ -587,7 +608,7 @@ public class V10LiftAPI {
continue;
}
s = (Sign) bs;
if (s.getLine(3).equals(ChatColor.MAGIC + "Defect!")) {
if (s.getLine(3).equals(ConfigUtil.getColored("DefectText"))) {
s.setLine(3, ls.getOldText());
s.update();
ls.setOldText(null);
@ -656,9 +677,8 @@ public class V10LiftAPI {
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setOffline").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
if (!(bs instanceof Sign)) continue;
sign = (Sign) bs;
//TODO Add defaults
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue;
sign.setLine(3, ChatColor.RED + "Disabled");
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) continue;
sign.setLine(3, ConfigUtil.getColored("DisabledText"));
sign.update();
}
@ -672,8 +692,7 @@ public class V10LiftAPI {
}
sign = (Sign) bs;
ls.setOldText(sign.getLine(3));
//TODO Add defaults
sign.setLine(3, ChatColor.RED + "Disabled");
sign.setLine(3, ConfigUtil.getColored("DisabledText"));
sign.update();
}
} else {
@ -681,8 +700,7 @@ public class V10LiftAPI {
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at setOffline").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
if (!(bs instanceof Sign)) continue;
sign = (Sign) bs;
//TODO Add defaults
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue;
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) continue;
sign.setLine(3, "");
sign.update();
}

View file

@ -5,7 +5,9 @@ import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import org.bukkit.*;
import org.bukkit.block.Block;
@ -227,9 +229,17 @@ public class V10LiftCommand implements CommandExecutor {
return true;
}
//TODO Add defaults to config!!!
int masterAmount = 2;
Material masterItem = Material.DIAMOND;
int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("MasterRepairAmount");
Optional<XMaterial> mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("MasterRepairItem"), "MasterRepairItem is null"));
if (!mat.isPresent()) {
Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!");
return true;
}
Material masterItem = mat.get().parseMaterial();
if (masterItem == null) {
Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!");
return true;
}
if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) {
if (!p.getInventory().contains(masterItem)) {
sender.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!");
@ -662,8 +672,7 @@ public class V10LiftCommand implements CommandExecutor {
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at edit command").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
if (!(bs instanceof Sign)) continue;
sign = (Sign) bs;
//TODO Add defaults
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue;
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) continue;
sign.setLine(3, "");
sign.update();
}
@ -678,7 +687,6 @@ public class V10LiftCommand implements CommandExecutor {
continue;
}
sign = (Sign) bs;
//TODO Add defaults
sign.setLine(3, ls.getOldText());
sign.update();
ls.setOldText(null);
@ -712,8 +720,7 @@ public class V10LiftCommand implements CommandExecutor {
bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at edit command").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState();
if (!(bs instanceof Sign)) continue;
sign = (Sign) bs;
//TODO Add defaults
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue;
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) continue;
sign.setLine(3, ChatColor.RED + "Maintenance");
sign.update();
}
@ -729,8 +736,7 @@ public class V10LiftCommand implements CommandExecutor {
}
sign = (Sign) bs;
ls.setOldText(sign.getLine(3));
//TODO Add defaults
sign.setLine(3, ChatColor.RED + "Maintenance");
sign.setLine(3, ConfigUtil.getColored("MaintenanceText"));
sign.update();
}
sender.sendMessage(ChatColor.GREEN + "Editor turned on!");
@ -750,8 +756,10 @@ public class V10LiftCommand implements CommandExecutor {
sender.sendMessage(ChatColor.RED + "You don't have the permission to remove that lift.");
}
//TODO Fix ignoring of result
V10LiftPlugin.getAPI().removeLift(args[1]);
if (!V10LiftPlugin.getAPI().removeLift(args[1])) {
sender.sendMessage(ChatColor.RED + "The lift " + args[1] + " couldn't be removed!");
return true;
}
sender.sendMessage(ChatColor.GREEN + "The lift " + args[1] + " is removed successfully!");
return true;

View file

@ -4,6 +4,7 @@ import nl.SBDeveloper.V10Lift.API.Objects.Floor;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import org.bukkit.Bukkit;
@ -24,6 +25,8 @@ import org.bukkit.inventory.ItemStack;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
public class PlayerInteractListener implements Listener {
//BUTTON CLICK
@ -257,8 +260,7 @@ public class PlayerInteractListener implements Listener {
if (!(bs instanceof Sign)) return;
Sign sign = (Sign) bs;
//TODO Add defaults to config!
if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) return;
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) return;
String liftName = sign.getLine(1);
if (!DataManager.containsLift(liftName)) return;
@ -269,10 +271,18 @@ public class PlayerInteractListener implements Listener {
}
if (lift.isDefective()) {
//TODO Add defaults to config!!!
if (sign.getLine(3).equals(ChatColor.MAGIC + "Defect!") && p.hasPermission("v10lift.repair") && a == Action.RIGHT_CLICK_BLOCK) {
int masterAmount = 2;
Material masterItem = Material.DIAMOND;
if (sign.getLine(3).equals(ConfigUtil.getColored("DefectText")) && p.hasPermission("v10lift.repair") && a == Action.RIGHT_CLICK_BLOCK) {
int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("RepairAmount");
Optional<XMaterial> mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("RepairItem"), "RepairItem is null"));
if (!mat.isPresent()) {
Bukkit.getLogger().severe("[V10Lift] The material for RepairItem is undefined!");
return;
}
Material masterItem = mat.get().parseMaterial();
if (masterItem == null) {
Bukkit.getLogger().severe("[V10Lift] The material for RepairItem is undefined!");
return;
}
if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) {
if (!p.getInventory().contains(masterItem)) {
p.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!");

View file

@ -114,6 +114,8 @@ public class DataManager {
return editors.get(player);
}
public static LinkedHashMap<UUID, String> getEditors() { return editors; }
// //
public static void addMovingTask(String liftName, int taskid) {
movingTasks.put(liftName, taskid);

View file

@ -0,0 +1,14 @@
package nl.SBDeveloper.V10Lift.Utils;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import org.bukkit.ChatColor;
import javax.annotation.Nonnull;
import java.util.Objects;
public class ConfigUtil {
@Nonnull
public static String getColored(@Nonnull String path) {
return ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString(path), "Message " + path + " not found!"));
}
}

View file

@ -13,6 +13,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.SQLException;
import java.util.Objects;
public class V10LiftPlugin extends JavaPlugin {
@ -38,7 +39,7 @@ public class V10LiftPlugin extends JavaPlugin {
api = new V10LiftAPI();
getCommand("v10lift").setExecutor(new V10LiftCommand());
Objects.requireNonNull(getCommand("v10lift"), "Internal error! Command not found.").setExecutor(new V10LiftCommand());
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockBreakListener(), this);

View file

@ -1,4 +1,7 @@
SignText: "[v10lift]"
DefectText: "&kDefect!"
DisabledText: "&cDisabled"
MaintenanceText: "&cMaintenance"
DefectRate: 0.0
RepairItem: REDSTONE
RepairAmount: 5