Compare commits
No commits in common. "225adf035459d274e0a9af5c1d4f2b418a1038cb" and "1cc787230cce389f6c6a4b0410c386532bf84785" have entirely different histories.
225adf0354
...
1cc787230c
13 changed files with 48 additions and 77 deletions
|
@ -59,7 +59,7 @@ public record TweaksConfig(
|
||||||
|
|
||||||
Map<String, Object> knockbackModifiers
|
Map<String, Object> knockbackModifiers
|
||||||
) {
|
) {
|
||||||
public static final int CONFIG_VERSION = 2;
|
public static final int CONFIG_VERSION = 1;
|
||||||
private static TweaksConfig config;
|
private static TweaksConfig config;
|
||||||
|
|
||||||
public static TweaksConfig getConfig() {
|
public static TweaksConfig getConfig() {
|
||||||
|
@ -72,12 +72,11 @@ public record TweaksConfig(
|
||||||
|
|
||||||
int configVersion = config.getInt("magic number don't modify this", 0);
|
int configVersion = config.getInt("magic number don't modify this", 0);
|
||||||
RuntimeException exception = new RuntimeException("Config version is %d, expected %d".formatted(configVersion, CONFIG_VERSION));
|
RuntimeException exception = new RuntimeException("Config version is %d, expected %d".formatted(configVersion, CONFIG_VERSION));
|
||||||
|
|
||||||
if (configVersion == 0) {
|
if (configVersion == 0) {
|
||||||
throw exception;
|
throw exception;
|
||||||
} else if (configVersion < CONFIG_VERSION) {
|
|
||||||
throw new RuntimeException("Please follow update instructions https://www.spigotmc.org/resources/tweaks724.121057/updates", exception);
|
|
||||||
} else if (configVersion > CONFIG_VERSION) {
|
} else if (configVersion > CONFIG_VERSION) {
|
||||||
|
throw new RuntimeException("Please follow update instructions", exception);
|
||||||
|
} else if (configVersion < CONFIG_VERSION) {
|
||||||
throw new RuntimeException("Did you downgrade the plugin? Remove config.yml and let the plugin re-create it", exception);
|
throw new RuntimeException("Did you downgrade the plugin? Remove config.yml and let the plugin re-create it", exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import eu.m724.tweaks.door.DoorKnockListener;
|
||||||
import eu.m724.tweaks.door.DoorOpenListener;
|
import eu.m724.tweaks.door.DoorOpenListener;
|
||||||
import eu.m724.tweaks.full.FullListener;
|
import eu.m724.tweaks.full.FullListener;
|
||||||
import eu.m724.tweaks.hardcore.HardcoreManager;
|
import eu.m724.tweaks.hardcore.HardcoreManager;
|
||||||
import eu.m724.tweaks.knockback.KnockbackListener;
|
|
||||||
import eu.m724.tweaks.motd.MotdManager;
|
import eu.m724.tweaks.motd.MotdManager;
|
||||||
import eu.m724.tweaks.ping.F3NameListener;
|
import eu.m724.tweaks.ping.F3NameListener;
|
||||||
import eu.m724.tweaks.ping.PingChecker;
|
import eu.m724.tweaks.ping.PingChecker;
|
||||||
|
@ -126,9 +125,6 @@ public class TweaksPlugin extends MStatsPlugin {
|
||||||
new RedstoneManager(this).init(getCommand("retstone"));
|
new RedstoneManager(this).init(getCommand("retstone"));
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.fine("Enabling Knockback");
|
|
||||||
new KnockbackListener(this);
|
|
||||||
|
|
||||||
/* end modules */
|
/* end modules */
|
||||||
|
|
||||||
if (config.metrics()) {
|
if (config.metrics()) {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
package eu.m724.tweaks.auth;
|
package eu.m724.tweaks.auth;
|
||||||
|
|
||||||
import eu.m724.tweaks.Language;
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksConfig;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
@ -51,7 +50,7 @@ public class AuthCommands implements CommandExecutor {
|
||||||
.underlined(true)
|
.underlined(true)
|
||||||
.color(ChatColor.GRAY)
|
.color(ChatColor.GRAY)
|
||||||
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, hostname))
|
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, hostname))
|
||||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(Language.getString("clickToCopy"))))
|
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to copy")))
|
||||||
.build();
|
.build();
|
||||||
sender.spigot().sendMessage(component);
|
sender.spigot().sendMessage(component);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,11 +19,12 @@ public class AuthStorage {
|
||||||
private final File keysDirectory;
|
private final File keysDirectory;
|
||||||
|
|
||||||
AuthStorage(Plugin plugin) {
|
AuthStorage(Plugin plugin) {
|
||||||
File directory = new File(plugin.getDataFolder(), "storage/auth");
|
File directory = new File(plugin.getDataFolder(), "auth storage");
|
||||||
this.playersDirectory = new File(directory, "players");
|
this.playersDirectory = new File(directory, "players");
|
||||||
this.keysDirectory = new File(directory, "keys");
|
this.keysDirectory = new File(directory, "keys");
|
||||||
|
|
||||||
keysDirectory.mkdirs();
|
directory.mkdir();
|
||||||
|
keysDirectory.mkdir();
|
||||||
playersDirectory.mkdir();
|
playersDirectory.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.bukkit.plugin.Plugin;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ChatManager {
|
public class ChatManager {
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
@ -74,7 +75,7 @@ public class ChatManager {
|
||||||
if (id.equals(defaultRoom)) {
|
if (id.equals(defaultRoom)) {
|
||||||
chatRoom = new ChatRoom(defaultRoom, null, null);
|
chatRoom = new ChatRoom(defaultRoom, null, null);
|
||||||
} else {
|
} else {
|
||||||
chatRoom = ChatRoomLoader.load(id);
|
chatRoom = ChatRoomLoader.load(plugin, id);
|
||||||
}
|
}
|
||||||
roomIdMap.put(id, chatRoom);
|
roomIdMap.put(id, chatRoom);
|
||||||
}
|
}
|
||||||
|
@ -171,17 +172,17 @@ public class ChatManager {
|
||||||
throw new ChatRoomExistsException();
|
throw new ChatRoomExistsException();
|
||||||
|
|
||||||
ChatRoom chatRoom = new ChatRoom(id, password, owner);
|
ChatRoom chatRoom = new ChatRoom(id, password, owner);
|
||||||
ChatRoomLoader.save(chatRoom);
|
ChatRoomLoader.save(plugin, chatRoom);
|
||||||
return chatRoom;
|
return chatRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveChatRoom(ChatRoom chatRoom) throws IOException {
|
void saveChatRoom(ChatRoom chatRoom) throws IOException {
|
||||||
ChatRoomLoader.save(chatRoom);
|
ChatRoomLoader.save(plugin, chatRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteChatRoom(ChatRoom chatRoom) {
|
public void deleteChatRoom(ChatRoom chatRoom) {
|
||||||
roomIdMap.remove(chatRoom.id);
|
roomIdMap.remove(chatRoom.id);
|
||||||
ChatRoomLoader.getFile(chatRoom.id).delete();
|
ChatRoomLoader.getFile(plugin, chatRoom.id).delete();
|
||||||
chatRoom.players.forEach(player -> setPlayerChatRoom(getById(defaultRoom), player));
|
chatRoom.players.forEach(player -> setPlayerChatRoom(getById(defaultRoom), player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,25 +13,23 @@ import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ChatRoomLoader {
|
public class ChatRoomLoader {
|
||||||
private static File chatRoomsDir;
|
|
||||||
|
|
||||||
static void init(Plugin plugin) {
|
|
||||||
chatRoomsDir = new File(plugin.getDataFolder(), "storage/rooms");
|
|
||||||
chatRoomsDir.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the file of persistent storage of a chat room
|
* Get the file of persistent storage of a chat room
|
||||||
* @return the file or null if ID is invalid
|
* @return the file or null if ID is invalid
|
||||||
*/
|
*/
|
||||||
static File getFile(String id) {
|
static File getFile(Plugin plugin, String id) {
|
||||||
|
Path chatRoomsPath = Paths.get(plugin.getDataFolder().getPath(), "rooms");
|
||||||
|
chatRoomsPath.toFile().mkdirs();
|
||||||
|
|
||||||
if (validateId(id) != 0)
|
if (validateId(id) != 0)
|
||||||
throw new RuntimeException("Invalid id: " + id);
|
throw new RuntimeException("Invalid id: " + id);
|
||||||
|
|
||||||
return new File(chatRoomsDir, id + ".yml");
|
return Paths.get(chatRoomsPath.toFile().getPath(), id + ".yml").toFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,8 +62,8 @@ public class ChatRoomLoader {
|
||||||
* @param id the id of the chat room
|
* @param id the id of the chat room
|
||||||
* @return the chat room or null if no such chat room
|
* @return the chat room or null if no such chat room
|
||||||
*/
|
*/
|
||||||
static ChatRoom load(String id) {
|
static ChatRoom load(Plugin plugin, String id) {
|
||||||
File chatRoomFile = getFile(id);
|
File chatRoomFile = getFile(plugin, id);
|
||||||
if (!chatRoomFile.exists()) return null;
|
if (!chatRoomFile.exists()) return null;
|
||||||
|
|
||||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(chatRoomFile);
|
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(chatRoomFile);
|
||||||
|
@ -91,15 +89,14 @@ public class ChatRoomLoader {
|
||||||
*
|
*
|
||||||
* @throws IOException if saving failed
|
* @throws IOException if saving failed
|
||||||
*/
|
*/
|
||||||
static void save(ChatRoom chatRoom) throws IOException {
|
static void save(Plugin plugin, ChatRoom chatRoom) throws IOException {
|
||||||
YamlConfiguration configuration = new YamlConfiguration();
|
YamlConfiguration configuration = new YamlConfiguration();
|
||||||
configuration.set("password", chatRoom.password);
|
configuration.set("password", chatRoom.password);
|
||||||
configuration.set("color", chatRoom.color.getName());
|
configuration.set("color", chatRoom.color.getName());
|
||||||
// TODO consider just making this str to make it easier
|
|
||||||
configuration.set("owner.msb", chatRoom.owner.getUniqueId().getMostSignificantBits());
|
configuration.set("owner.msb", chatRoom.owner.getUniqueId().getMostSignificantBits());
|
||||||
configuration.set("owner.lsb", chatRoom.owner.getUniqueId().getLeastSignificantBits());
|
configuration.set("owner.lsb", chatRoom.owner.getUniqueId().getLeastSignificantBits());
|
||||||
|
|
||||||
File chatRoomFile = getFile(chatRoom.id);
|
File chatRoomFile = getFile(plugin, chatRoom.id);
|
||||||
configuration.save(chatRoomFile);
|
configuration.save(chatRoomFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,6 @@
|
||||||
package eu.m724.tweaks.redstone;
|
package eu.m724.tweaks.redstone;
|
||||||
|
|
||||||
import eu.m724.tweaks.DebugLogger;
|
import eu.m724.tweaks.DebugLogger;
|
||||||
import eu.m724.tweaks.Language;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
|
@ -51,19 +45,13 @@ public class RedstoneListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
if (!event.getPlayer().isSneaking()) return;
|
if (event.getClickedBlock() == null) return;
|
||||||
|
|
||||||
var id = redstoneRepeaters.getId(event.getClickedBlock());
|
var id = redstoneRepeaters.getId(event.getClickedBlock());
|
||||||
if (id == Integer.MIN_VALUE) return;
|
if (id == Integer.MIN_VALUE) return;
|
||||||
|
|
||||||
// TODO find a less lame way of showing ID
|
// TODO find a less lame way of showing ID
|
||||||
var component = new ComponentBuilder("Repeater ID: ").color(ChatColor.GOLD)
|
event.getPlayer().sendMessage("Repeater ID: " + id);
|
||||||
.append(String.valueOf(id)).color(ChatColor.AQUA)
|
|
||||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(Language.getString("clickToCopy"))))
|
|
||||||
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, String.valueOf(id)))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
event.getPlayer().spigot().sendMessage(component);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class RedstoneManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(PluginCommand command) {
|
public void init(PluginCommand command) {
|
||||||
RedstoneStore.init(plugin);
|
Store.init(plugin);
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new RedstoneListener(redstoneRepeaters), plugin);
|
plugin.getServer().getPluginManager().registerEvents(new RedstoneListener(redstoneRepeaters), plugin);
|
||||||
command.setExecutor(new RedstoneCommands(redstoneRepeaters));
|
command.setExecutor(new RedstoneCommands(redstoneRepeaters));
|
||||||
|
|
|
@ -8,7 +8,6 @@ package eu.m724.tweaks.redstone;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import eu.m724.tweaks.DebugLogger;
|
|
||||||
import eu.m724.tweaks.Language;
|
import eu.m724.tweaks.Language;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -66,7 +65,7 @@ public class RedstoneRepeaters {
|
||||||
repeatersById.put(repeaterId, block.getLocation());
|
repeatersById.put(repeaterId, block.getLocation());
|
||||||
block.setMetadata("rid", new FixedMetadataValue(plugin, repeaterId));
|
block.setMetadata("rid", new FixedMetadataValue(plugin, repeaterId));
|
||||||
|
|
||||||
RedstoneStore.getInstance().saveRepeaterData(block.getLocation(), repeaterId, (byte) 0);
|
Store.getInstance().saveRepeaterData(block.getLocation(), repeaterId, (byte) 0);
|
||||||
|
|
||||||
return repeaterId;
|
return repeaterId;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +79,7 @@ public class RedstoneRepeaters {
|
||||||
if (location == null) return;
|
if (location == null) return;
|
||||||
repeatersByPower.remove(repeaterId);
|
repeatersByPower.remove(repeaterId);
|
||||||
|
|
||||||
RedstoneStore.getInstance().deleteSavedRepeaterData(location);
|
Store.getInstance().deleteSavedRepeaterData(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get functions */
|
/* Get functions */
|
||||||
|
@ -90,7 +89,7 @@ public class RedstoneRepeaters {
|
||||||
// if not, we're not loading because it's loaded as the block is
|
// if not, we're not loading because it's loaded as the block is
|
||||||
var loc = repeatersById.get(repeaterId);
|
var loc = repeatersById.get(repeaterId);
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
DebugLogger.fine("isValid: Delete because no loc");
|
System.err.println("Delete because no loc");
|
||||||
delete(repeaterId);
|
delete(repeaterId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +101,6 @@ public class RedstoneRepeaters {
|
||||||
|
|
||||||
// check if the block is correct type
|
// check if the block is correct type
|
||||||
if (loc.getBlock().getType() != Material.DAYLIGHT_DETECTOR) {
|
if (loc.getBlock().getType() != Material.DAYLIGHT_DETECTOR) {
|
||||||
DebugLogger.fine("isValid: Delete because not sensor");
|
|
||||||
delete(repeaterId);
|
delete(repeaterId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +108,7 @@ public class RedstoneRepeaters {
|
||||||
// check if the block has the same ID bound
|
// check if the block has the same ID bound
|
||||||
var meta = loc.getBlock().getMetadata("rid");
|
var meta = loc.getBlock().getMetadata("rid");
|
||||||
if (meta.isEmpty() || meta.getFirst().asInt() != repeaterId) {
|
if (meta.isEmpty() || meta.getFirst().asInt() != repeaterId) {
|
||||||
DebugLogger.fine("isValid: Delete because no meta");
|
System.err.println("Delete because no meta");
|
||||||
delete(repeaterId);
|
delete(repeaterId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +126,7 @@ public class RedstoneRepeaters {
|
||||||
|
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
// not in memory, check if repeater
|
// not in memory, check if repeater
|
||||||
var d = RedstoneStore.getInstance().getSavedRepeaterData(block.getLocation());
|
var d = Store.getInstance().getSavedRepeaterData(block.getLocation());
|
||||||
|
|
||||||
if (d == null) {
|
if (d == null) {
|
||||||
block.setMetadata("rid", new FixedMetadataValue(plugin, Integer.MIN_VALUE));
|
block.setMetadata("rid", new FixedMetadataValue(plugin, Integer.MIN_VALUE));
|
||||||
|
@ -155,13 +153,12 @@ public class RedstoneRepeaters {
|
||||||
|
|
||||||
var storedId = location.getBlock().getMetadata("rid").getFirst().asInt();
|
var storedId = location.getBlock().getMetadata("rid").getFirst().asInt();
|
||||||
if (storedId != repeaterId) {
|
if (storedId != repeaterId) {
|
||||||
DebugLogger.fine("attempted retrieve, but doesn't exist, deleting " + repeaterId);
|
System.out.println("retrieved but not exitt");
|
||||||
delete(repeaterId);
|
delete(repeaterId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.fine("retrieved " + repeaterId);
|
System.out.println("retrieved exist " + repeaterId);
|
||||||
|
|
||||||
return location.getBlock();
|
return location.getBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,21 +170,20 @@ public class RedstoneRepeaters {
|
||||||
|
|
||||||
block.getWorld().spawnParticle(Particle.LAVA, block.getLocation().add(0.5, 0.5, 0.5), 3);
|
block.getWorld().spawnParticle(Particle.LAVA, block.getLocation().add(0.5, 0.5, 0.5), 3);
|
||||||
|
|
||||||
var power = (byte) block.getBlockPower();
|
System.out.println("Okay I got in power" + block.getBlockPower());
|
||||||
DebugLogger.fine("Got " + repeaterId + " receives " + power);
|
return (byte) block.getBlockPower();
|
||||||
return power;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte getOutboundPower(int repeaterId) {
|
byte getOutboundPower(int repeaterId) {
|
||||||
var block = getBlock(repeaterId);
|
var block = getBlock(repeaterId);
|
||||||
if (block == null) return -1;
|
if (block == null) return -1;
|
||||||
|
|
||||||
var power = repeatersByPower.getOrDefault(repeaterId, (byte) 0);
|
System.out.println("Okay I got out power" + repeatersByPower.get(repeaterId));
|
||||||
DebugLogger.fine("Got " + repeaterId + " outputs " + power);
|
return repeatersByPower.getOrDefault(repeaterId, (byte) 0);
|
||||||
return power;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPower(int repeaterId, byte power) {
|
void setPower(int repeaterId, byte power) {
|
||||||
|
System.out.println(power);
|
||||||
if (power < 0 || power > 15)
|
if (power < 0 || power > 15)
|
||||||
throw new IllegalArgumentException("Power should be 0-15, but is " + power);
|
throw new IllegalArgumentException("Power should be 0-15, but is " + power);
|
||||||
|
|
||||||
|
@ -201,6 +197,6 @@ public class RedstoneRepeaters {
|
||||||
|
|
||||||
block.getWorld().spawnParticle(Particle.LAVA, block.getLocation().add(0.5, 0.5, 0.5), 3);
|
block.getWorld().spawnParticle(Particle.LAVA, block.getLocation().add(0.5, 0.5, 0.5), 3);
|
||||||
|
|
||||||
DebugLogger.fine("Set power of " + repeaterId + " to " + power);
|
System.out.println("Okay I set power");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,6 @@
|
||||||
package eu.m724.tweaks.redstone;
|
package eu.m724.tweaks.redstone;
|
||||||
|
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import eu.m724.tweaks.DebugLogger;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
@ -16,23 +15,23 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class RedstoneStore {
|
public class Store {
|
||||||
private static RedstoneStore INSTANCE;
|
private static Store INSTANCE;
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
private final File directory;
|
private final File directory;
|
||||||
|
|
||||||
private RedstoneStore(Plugin plugin) {
|
private Store(Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.directory = new File(plugin.getDataFolder(), "storage/redstone");
|
this.directory = new File(plugin.getDataFolder(), "storage/redstone");
|
||||||
directory.mkdirs();
|
directory.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init(Plugin plugin) {
|
static void init(Plugin plugin) {
|
||||||
INSTANCE = new RedstoneStore(plugin);
|
INSTANCE = new Store(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RedstoneStore getInstance() {
|
static Store getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +51,12 @@ public class RedstoneStore {
|
||||||
var repeaterId = Ints.fromByteArray(bytes) & ~0xF;
|
var repeaterId = Ints.fromByteArray(bytes) & ~0xF;
|
||||||
var powerLevel = (byte) (bytes[3] & 0xF);
|
var powerLevel = (byte) (bytes[3] & 0xF);
|
||||||
|
|
||||||
DebugLogger.fine("load " + location + " " + repeaterId + " " + powerLevel);
|
|
||||||
|
|
||||||
return Pair.of(repeaterId, powerLevel);
|
return Pair.of(repeaterId, powerLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveRepeaterData(Location location, int repeaterId, byte powerLevel) {
|
void saveRepeaterData(Location location, int repeaterId, byte powerLevel) {
|
||||||
var file = getFile(location);
|
var file = getFile(location);
|
||||||
|
System.out.println(file);
|
||||||
byte[] bytes = Ints.toByteArray((repeaterId & ~0xF) | (powerLevel & 0xF));
|
byte[] bytes = Ints.toByteArray((repeaterId & ~0xF) | (powerLevel & 0xF));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -66,8 +64,6 @@ public class RedstoneStore {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Saving repeater data", e);
|
throw new RuntimeException("Saving repeater data", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.fine("save " + location + " " + repeaterId + " " + powerLevel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteSavedRepeaterData(Location location) {
|
void deleteSavedRepeaterData(Location location) {
|
|
@ -28,7 +28,7 @@ public class UpdaterManager {
|
||||||
|
|
||||||
public UpdaterManager(Plugin plugin) {
|
public UpdaterManager(Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
cacheFile = new File(plugin.getDataFolder(), "storage/updater");
|
cacheFile = new File(plugin.getDataFolder(), "cache/updater");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(PluginCommand updatesCommand){
|
public void init(PluginCommand updatesCommand){
|
||||||
|
|
|
@ -120,4 +120,4 @@ knockback:
|
||||||
# Finally, thank you for downloading Tweaks724, I hope you enjoy!
|
# Finally, thank you for downloading Tweaks724, I hope you enjoy!
|
||||||
|
|
||||||
# Don't modify unless told to
|
# Don't modify unless told to
|
||||||
magic number don't modify this: 2
|
magic number don't modify this: 1
|
|
@ -30,6 +30,4 @@ authKickWrongKey = You're connecting to the wrong server address. You must conne
|
||||||
# If force is enabled and player is not registered. Changing this reveals you're using this plugin
|
# If force is enabled and player is not registered. Changing this reveals you're using this plugin
|
||||||
authKickUnregistered = You are not whitelisted on this server!
|
authKickUnregistered = You are not whitelisted on this server!
|
||||||
|
|
||||||
retstoneBlockItem = Online redstone block
|
retstoneBlockItem = Online redstone block
|
||||||
|
|
||||||
clickToCopy = Click to copy to clipboard
|
|
Loading…
Reference in a new issue