mirror of
https://github.com/songoda/EpicFurnaces.git
synced 2024-12-02 23:03:36 +01:00
Redid the remote system. It was bad.
This commit is contained in:
parent
29a3e845b3
commit
d48fddfeb2
@ -42,6 +42,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EpicFurnaces extends SongodaPlugin {
|
||||
|
||||
@ -225,12 +226,22 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
String placedByStr = row.get("placedBy").asString();
|
||||
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)
|
||||
.setLevel(levelManager.getLevel(row.get("level").asInt()))
|
||||
.setNickname(row.get("nickname").asString())
|
||||
.setUses(row.get("uses").asInt())
|
||||
.setToLevel(row.get("tolevel").asInt())
|
||||
.setAccessList(row.get("accesslist").asStringList())
|
||||
.setAccessList(usableList)
|
||||
.setPlacedBy(placedBy).build();
|
||||
|
||||
furnaceManager.addFurnace(furnace);
|
||||
|
@ -4,9 +4,12 @@ import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -22,37 +25,39 @@ public class CommandRemote extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
|
||||
if (!Settings.REMOTE.getBoolean() || !sender.hasPermission("EpicFurnaces.Remote")) {
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (args.length < 1) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
StringBuilder name = new StringBuilder();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
name.append(" ").append(args[i]);
|
||||
String name = String.join(" ", args);
|
||||
Furnace furnace = plugin.getFurnaceManager().getFurnaces().values()
|
||||
.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())) {
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
continue;
|
||||
}
|
||||
for (UUID uuid : furnace.getAccessList()) {
|
||||
if (!uuid.equals(((Player) sender).getUniqueId())) {
|
||||
continue;
|
||||
for (UUID uuid : furnace.getAccessList()) {
|
||||
if (!uuid.equals(((Player) sender).getUniqueId())) continue;
|
||||
Block b = furnace.getLocation().getBlock();
|
||||
b.getChunk().load();
|
||||
org.bukkit.block.Furnace furnaceBlock = (org.bukkit.block.Furnace) b.getState();
|
||||
Inventory inventory = furnaceBlock.getInventory();
|
||||
((Player) sender).openInventory(inventory);
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
if (inventory.getViewers().size() == 0) {
|
||||
b.getChunk().unload();
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
Block b = furnace.getLocation().getBlock();
|
||||
org.bukkit.block.Furnace furnaceBlock = (org.bukkit.block.Furnace) b.getState();
|
||||
((Player) sender).openInventory(furnaceBlock.getInventory());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
}.runTaskTimer(plugin, 5L, 5L);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
plugin.getLocale().getMessage("event.remote.notfound").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class Furnace {
|
||||
private int uses, tolevel, radiusOverheatLast, radiusFuelshareLast = 0;
|
||||
private final List<Location> radiusOverheat = 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<>();
|
||||
|
||||
public Furnace(Location location) {
|
||||
@ -210,20 +210,9 @@ public class Furnace {
|
||||
|
||||
|
||||
public List<UUID> getAccessList() {
|
||||
List<UUID> list = new ArrayList<>();
|
||||
for (String line : accessList) {
|
||||
String[] halfs = line.split(":");
|
||||
list.add(UUID.fromString(halfs[0]));
|
||||
}
|
||||
|
||||
return list;
|
||||
return Collections.unmodifiableList(accessList);
|
||||
}
|
||||
|
||||
public List<String> getRawAccessList() {
|
||||
return new ArrayList<>(accessList);
|
||||
}
|
||||
|
||||
|
||||
public int getPerformanceTotal(Material material) {
|
||||
String cap = (material.name().contains("BLAST") || material.name().contains("SMOKER") ? "100" : "200");
|
||||
String equation = "(" + level.getPerformance() + " / 100) * " + cap;
|
||||
@ -243,24 +232,14 @@ public class Furnace {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getOriginalAccessList() {
|
||||
return Collections.unmodifiableList(accessList);
|
||||
public boolean addToAccessList(OfflinePlayer player) {
|
||||
return addToAccessList(player.getUniqueId());
|
||||
}
|
||||
|
||||
|
||||
public boolean addToAccessList(Player player) {
|
||||
String formatted = player.getUniqueId().toString() + ":" + player.getName();
|
||||
if (accessList.contains(formatted)) return false;
|
||||
return addToAccessList(formatted);
|
||||
public boolean addToAccessList(UUID uuid) {
|
||||
return accessList.add(uuid);
|
||||
}
|
||||
|
||||
public boolean addToAccessList(String formatted) {
|
||||
if (accessList.contains(formatted)) return false;
|
||||
return accessList.add(formatted);
|
||||
}
|
||||
|
||||
|
||||
public boolean removeFromAccessList(String string) {
|
||||
return accessList.remove(string);
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ public class FurnaceBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FurnaceBuilder setAccessList(List<String> accessList) {
|
||||
for (String line : accessList)
|
||||
this.furnace.addToAccessList(line);
|
||||
public FurnaceBuilder setAccessList(List<UUID> accessList) {
|
||||
for (UUID uuid : accessList)
|
||||
this.furnace.addToAccessList(uuid);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import com.songoda.epicfurnaces.settings.Settings;
|
||||
import com.songoda.epicfurnaces.utils.CostType;
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -19,6 +20,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GUIOverview extends Gui {
|
||||
|
||||
@ -238,14 +240,9 @@ public class GUIOverview extends Gui {
|
||||
|
||||
lorehook.add("");
|
||||
lorehook.add(plugin.getLocale().getMessage("interface.furnace.remotelist").getMessage());
|
||||
for (String line : furnace.getRawAccessList()) {
|
||||
String[] halfs = line.split(":");
|
||||
String name = halfs[1];
|
||||
Player remotePlayer = Bukkit.getPlayer(halfs[0]);
|
||||
if (remotePlayer != null) {
|
||||
name = remotePlayer.getDisplayName();
|
||||
}
|
||||
lorehook.add(Methods.formatText("&6" + name));
|
||||
for (UUID uuid : furnace.getAccessList()) {
|
||||
OfflinePlayer remotePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
lorehook.add(Methods.formatText("&6" + remotePlayer.getName()));
|
||||
}
|
||||
return lorehook;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import com.songoda.epicfurnaces.furnace.Furnace;
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class Storage {
|
||||
|
||||
@ -42,7 +44,7 @@ public abstract class Storage {
|
||||
new StorageItem("uses", furnace.getUses()),
|
||||
new StorageItem("tolevel", furnace.getTolevel()),
|
||||
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()));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user