Redid the remote system. It was bad.

This commit is contained in:
Brianna 2020-04-21 05:55:26 -04:00
parent 29a3e845b3
commit d48fddfeb2
6 changed files with 55 additions and 61 deletions

View File

@ -42,6 +42,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class EpicFurnaces extends SongodaPlugin { public class EpicFurnaces extends SongodaPlugin {
@ -225,12 +226,22 @@ public class EpicFurnaces extends SongodaPlugin {
String placedByStr = row.get("placedBy").asString(); String placedByStr = row.get("placedBy").asString();
UUID placedBy = placedByStr == null ? null : UUID.fromString(placedByStr); UUID placedBy = placedByStr == null ? null : UUID.fromString(placedByStr);
List<String> list = row.get("accesslist").asStringList();
if (!list.isEmpty()) {
for (String uuid : new ArrayList<>(list))
if (uuid.contains(":")) {
list = new ArrayList<>();
break;
}
}
List<UUID> usableList = list.stream().map(UUID::fromString).collect(Collectors.toList());
Furnace furnace = new FurnaceBuilder(location) Furnace furnace = new FurnaceBuilder(location)
.setLevel(levelManager.getLevel(row.get("level").asInt())) .setLevel(levelManager.getLevel(row.get("level").asInt()))
.setNickname(row.get("nickname").asString()) .setNickname(row.get("nickname").asString())
.setUses(row.get("uses").asInt()) .setUses(row.get("uses").asInt())
.setToLevel(row.get("tolevel").asInt()) .setToLevel(row.get("tolevel").asInt())
.setAccessList(row.get("accesslist").asStringList()) .setAccessList(usableList)
.setPlacedBy(placedBy).build(); .setPlacedBy(placedBy).build();
furnaceManager.addFurnace(furnace); furnaceManager.addFurnace(furnace);

View File

@ -4,9 +4,12 @@ import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.EpicFurnaces;
import com.songoda.epicfurnaces.furnace.Furnace; import com.songoda.epicfurnaces.furnace.Furnace;
import com.songoda.epicfurnaces.settings.Settings; import com.songoda.epicfurnaces.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -22,37 +25,39 @@ public class CommandRemote extends AbstractCommand {
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (!Settings.REMOTE.getBoolean() || !sender.hasPermission("EpicFurnaces.Remote")) { if (!Settings.REMOTE.getBoolean() || !sender.hasPermission("EpicFurnaces.Remote")) {
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender); plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
if (args.length < 1) return ReturnType.SYNTAX_ERROR; if (args.length < 1) return ReturnType.SYNTAX_ERROR;
StringBuilder name = new StringBuilder(); String name = String.join(" ", args);
for (int i = 0; i < args.length; i++) { Furnace furnace = plugin.getFurnaceManager().getFurnaces().values()
name.append(" ").append(args[i]); .stream().filter(f -> f.getNickname() != null
&& f.getNickname().equalsIgnoreCase(name)).findFirst().orElse(null);
if (furnace == null) {
plugin.getLocale().getMessage("event.remote.notfound").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} }
name = new StringBuilder(name.toString().trim());
for (Furnace furnace : plugin.getFurnaceManager().getFurnaces().values()) {
if (furnace.getNickname() == null) continue;
if (!furnace.getNickname().equalsIgnoreCase(name.toString())) { for (UUID uuid : furnace.getAccessList()) {
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender); if (!uuid.equals(((Player) sender).getUniqueId())) continue;
continue; Block b = furnace.getLocation().getBlock();
} b.getChunk().load();
for (UUID uuid : furnace.getAccessList()) { org.bukkit.block.Furnace furnaceBlock = (org.bukkit.block.Furnace) b.getState();
if (!uuid.equals(((Player) sender).getUniqueId())) { Inventory inventory = furnaceBlock.getInventory();
continue; ((Player) sender).openInventory(inventory);
new BukkitRunnable() {
public void run() {
if (inventory.getViewers().size() == 0) {
b.getChunk().unload();
this.cancel();
}
} }
Block b = furnace.getLocation().getBlock(); }.runTaskTimer(plugin, 5L, 5L);
org.bukkit.block.Furnace furnaceBlock = (org.bukkit.block.Furnace) b.getState(); return ReturnType.SUCCESS;
((Player) sender).openInventory(furnaceBlock.getInventory());
return ReturnType.SUCCESS;
}
} }
plugin.getLocale().getMessage("event.remote.notfound").sendPrefixedMessage(sender); plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }

View File

@ -37,7 +37,7 @@ public class Furnace {
private int uses, tolevel, radiusOverheatLast, radiusFuelshareLast = 0; private int uses, tolevel, radiusOverheatLast, radiusFuelshareLast = 0;
private final List<Location> radiusOverheat = new ArrayList<>(); private final List<Location> radiusOverheat = new ArrayList<>();
private final List<Location> radiusFuelshare = new ArrayList<>(); private final List<Location> radiusFuelshare = new ArrayList<>();
private final List<String> accessList = new ArrayList<>(); private final List<UUID> accessList = new ArrayList<>();
private final Map<String, Integer> cache = new HashMap<>(); private final Map<String, Integer> cache = new HashMap<>();
public Furnace(Location location) { public Furnace(Location location) {
@ -210,20 +210,9 @@ public class Furnace {
public List<UUID> getAccessList() { public List<UUID> getAccessList() {
List<UUID> list = new ArrayList<>(); return Collections.unmodifiableList(accessList);
for (String line : accessList) {
String[] halfs = line.split(":");
list.add(UUID.fromString(halfs[0]));
}
return list;
} }
public List<String> getRawAccessList() {
return new ArrayList<>(accessList);
}
public int getPerformanceTotal(Material material) { public int getPerformanceTotal(Material material) {
String cap = (material.name().contains("BLAST") || material.name().contains("SMOKER") ? "100" : "200"); String cap = (material.name().contains("BLAST") || material.name().contains("SMOKER") ? "100" : "200");
String equation = "(" + level.getPerformance() + " / 100) * " + cap; String equation = "(" + level.getPerformance() + " / 100) * " + cap;
@ -243,24 +232,14 @@ public class Furnace {
return 0; return 0;
} }
public boolean addToAccessList(OfflinePlayer player) {
public List<String> getOriginalAccessList() { return addToAccessList(player.getUniqueId());
return Collections.unmodifiableList(accessList);
} }
public boolean addToAccessList(UUID uuid) {
public boolean addToAccessList(Player player) { return accessList.add(uuid);
String formatted = player.getUniqueId().toString() + ":" + player.getName();
if (accessList.contains(formatted)) return false;
return addToAccessList(formatted);
} }
public boolean addToAccessList(String formatted) {
if (accessList.contains(formatted)) return false;
return accessList.add(formatted);
}
public boolean removeFromAccessList(String string) { public boolean removeFromAccessList(String string) {
return accessList.remove(string); return accessList.remove(string);
} }

View File

@ -36,9 +36,9 @@ public class FurnaceBuilder {
return this; return this;
} }
public FurnaceBuilder setAccessList(List<String> accessList) { public FurnaceBuilder setAccessList(List<UUID> accessList) {
for (String line : accessList) for (UUID uuid : accessList)
this.furnace.addToAccessList(line); this.furnace.addToAccessList(uuid);
return this; return this;
} }

View File

@ -12,6 +12,7 @@ import com.songoda.epicfurnaces.settings.Settings;
import com.songoda.epicfurnaces.utils.CostType; import com.songoda.epicfurnaces.utils.CostType;
import com.songoda.epicfurnaces.utils.Methods; import com.songoda.epicfurnaces.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -19,6 +20,7 @@ import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID;
public class GUIOverview extends Gui { public class GUIOverview extends Gui {
@ -238,14 +240,9 @@ public class GUIOverview extends Gui {
lorehook.add(""); lorehook.add("");
lorehook.add(plugin.getLocale().getMessage("interface.furnace.remotelist").getMessage()); lorehook.add(plugin.getLocale().getMessage("interface.furnace.remotelist").getMessage());
for (String line : furnace.getRawAccessList()) { for (UUID uuid : furnace.getAccessList()) {
String[] halfs = line.split(":"); OfflinePlayer remotePlayer = Bukkit.getOfflinePlayer(uuid);
String name = halfs[1]; lorehook.add(Methods.formatText("&6" + remotePlayer.getName()));
Player remotePlayer = Bukkit.getPlayer(halfs[0]);
if (remotePlayer != null) {
name = remotePlayer.getDisplayName();
}
lorehook.add(Methods.formatText("&6" + name));
} }
return lorehook; return lorehook;
} }

View File

@ -7,6 +7,8 @@ import com.songoda.epicfurnaces.furnace.Furnace;
import com.songoda.epicfurnaces.utils.Methods; import com.songoda.epicfurnaces.utils.Methods;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public abstract class Storage { public abstract class Storage {
@ -42,7 +44,7 @@ public abstract class Storage {
new StorageItem("uses", furnace.getUses()), new StorageItem("uses", furnace.getUses()),
new StorageItem("tolevel", furnace.getTolevel()), new StorageItem("tolevel", furnace.getTolevel()),
new StorageItem("nickname", furnace.getNickname()), new StorageItem("nickname", furnace.getNickname()),
new StorageItem("accesslist", furnace.getOriginalAccessList()), new StorageItem("accesslist", furnace.getAccessList().stream().map(UUID::toString).collect(Collectors.toList())),
new StorageItem("placedby", furnace.getPlacedBy() == null ? null : furnace.getPlacedBy().toString())); new StorageItem("placedby", furnace.getPlacedBy() == null ? null : furnace.getPlacedBy().toString()));
} }