Compare commits

..

8 commits

Author SHA1 Message Date
225adf0354
Remove debug printlns
All checks were successful
/ build (push) Successful in 1m2s
2024-12-31 18:39:34 +01:00
812b16e4be
Click to copy repeater
Also added translation for copying
2024-12-31 18:15:09 +01:00
1acfcd273d
Forgot to enable knockback module 2024-12-31 17:07:51 +01:00
c92d4429da
Also move updater cache
From "cache/updater" to "storage/cache/updater"
2024-12-31 17:04:39 +01:00
6153da89a1
Fix wrong tip if wrong config version 2024-12-31 17:01:49 +01:00
3a6d1366ab
Bump config version because we're getting tons of changes 2024-12-31 16:38:33 +01:00
9e4125dd4e
Move chat storage
From "rooms" to "storage/rooms"
2024-12-31 16:37:32 +01:00
69cb2ef9af
Move auth storage
From "auth storage" to "storage/auth"
2024-12-31 16:29:39 +01:00
13 changed files with 77 additions and 48 deletions

View file

@ -59,7 +59,7 @@ public record TweaksConfig(
Map<String, Object> knockbackModifiers
) {
public static final int CONFIG_VERSION = 1;
public static final int CONFIG_VERSION = 2;
private static TweaksConfig config;
public static TweaksConfig getConfig() {
@ -72,11 +72,12 @@ public record TweaksConfig(
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));
if (configVersion == 0) {
throw exception;
} else if (configVersion > CONFIG_VERSION) {
throw new RuntimeException("Please follow update instructions", 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) {
throw new RuntimeException("Did you downgrade the plugin? Remove config.yml and let the plugin re-create it", exception);
}

View file

@ -14,6 +14,7 @@ import eu.m724.tweaks.door.DoorKnockListener;
import eu.m724.tweaks.door.DoorOpenListener;
import eu.m724.tweaks.full.FullListener;
import eu.m724.tweaks.hardcore.HardcoreManager;
import eu.m724.tweaks.knockback.KnockbackListener;
import eu.m724.tweaks.motd.MotdManager;
import eu.m724.tweaks.ping.F3NameListener;
import eu.m724.tweaks.ping.PingChecker;
@ -125,6 +126,9 @@ public class TweaksPlugin extends MStatsPlugin {
new RedstoneManager(this).init(getCommand("retstone"));
}
DebugLogger.fine("Enabling Knockback");
new KnockbackListener(this);
/* end modules */
if (config.metrics()) {

View file

@ -6,6 +6,7 @@
package eu.m724.tweaks.auth;
import eu.m724.tweaks.Language;
import eu.m724.tweaks.TweaksConfig;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
@ -50,7 +51,7 @@ public class AuthCommands implements CommandExecutor {
.underlined(true)
.color(ChatColor.GRAY)
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, hostname))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to copy")))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(Language.getString("clickToCopy"))))
.build();
sender.spigot().sendMessage(component);
} else {

View file

@ -19,12 +19,11 @@ public class AuthStorage {
private final File keysDirectory;
AuthStorage(Plugin plugin) {
File directory = new File(plugin.getDataFolder(), "auth storage");
File directory = new File(plugin.getDataFolder(), "storage/auth");
this.playersDirectory = new File(directory, "players");
this.keysDirectory = new File(directory, "keys");
directory.mkdir();
keysDirectory.mkdir();
keysDirectory.mkdirs();
playersDirectory.mkdir();
}

View file

@ -19,7 +19,6 @@ import org.bukkit.plugin.Plugin;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class ChatManager {
private final Plugin plugin;
@ -75,7 +74,7 @@ public class ChatManager {
if (id.equals(defaultRoom)) {
chatRoom = new ChatRoom(defaultRoom, null, null);
} else {
chatRoom = ChatRoomLoader.load(plugin, id);
chatRoom = ChatRoomLoader.load(id);
}
roomIdMap.put(id, chatRoom);
}
@ -172,17 +171,17 @@ public class ChatManager {
throw new ChatRoomExistsException();
ChatRoom chatRoom = new ChatRoom(id, password, owner);
ChatRoomLoader.save(plugin, chatRoom);
ChatRoomLoader.save(chatRoom);
return chatRoom;
}
void saveChatRoom(ChatRoom chatRoom) throws IOException {
ChatRoomLoader.save(plugin, chatRoom);
ChatRoomLoader.save(chatRoom);
}
public void deleteChatRoom(ChatRoom chatRoom) {
roomIdMap.remove(chatRoom.id);
ChatRoomLoader.getFile(plugin, chatRoom.id).delete();
ChatRoomLoader.getFile(chatRoom.id).delete();
chatRoom.players.forEach(player -> setPlayerChatRoom(getById(defaultRoom), player));
}

View file

@ -13,23 +13,25 @@ import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;
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
* @return the file or null if ID is invalid
*/
static File getFile(Plugin plugin, String id) {
Path chatRoomsPath = Paths.get(plugin.getDataFolder().getPath(), "rooms");
chatRoomsPath.toFile().mkdirs();
static File getFile(String id) {
if (validateId(id) != 0)
throw new RuntimeException("Invalid id: " + id);
return Paths.get(chatRoomsPath.toFile().getPath(), id + ".yml").toFile();
return new File(chatRoomsDir, id + ".yml");
}
/**
@ -62,8 +64,8 @@ public class ChatRoomLoader {
* @param id the id of the chat room
* @return the chat room or null if no such chat room
*/
static ChatRoom load(Plugin plugin, String id) {
File chatRoomFile = getFile(plugin, id);
static ChatRoom load(String id) {
File chatRoomFile = getFile(id);
if (!chatRoomFile.exists()) return null;
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(chatRoomFile);
@ -89,14 +91,15 @@ public class ChatRoomLoader {
*
* @throws IOException if saving failed
*/
static void save(Plugin plugin, ChatRoom chatRoom) throws IOException {
static void save(ChatRoom chatRoom) throws IOException {
YamlConfiguration configuration = new YamlConfiguration();
configuration.set("password", chatRoom.password);
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.lsb", chatRoom.owner.getUniqueId().getLeastSignificantBits());
File chatRoomFile = getFile(plugin, chatRoom.id);
File chatRoomFile = getFile(chatRoom.id);
configuration.save(chatRoomFile);
}
}

View file

@ -7,6 +7,12 @@
package eu.m724.tweaks.redstone;
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.Listener;
import org.bukkit.event.block.Action;
@ -45,13 +51,19 @@ public class RedstoneListener implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getClickedBlock() == null) return;
if (!event.getPlayer().isSneaking()) return;
var id = redstoneRepeaters.getId(event.getClickedBlock());
if (id == Integer.MIN_VALUE) return;
// TODO find a less lame way of showing ID
event.getPlayer().sendMessage("Repeater ID: " + id);
var component = new ComponentBuilder("Repeater ID: ").color(ChatColor.GOLD)
.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

View file

@ -29,7 +29,7 @@ public class RedstoneManager {
}
public void init(PluginCommand command) {
Store.init(plugin);
RedstoneStore.init(plugin);
plugin.getServer().getPluginManager().registerEvents(new RedstoneListener(redstoneRepeaters), plugin);
command.setExecutor(new RedstoneCommands(redstoneRepeaters));

View file

@ -8,6 +8,7 @@ package eu.m724.tweaks.redstone;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import eu.m724.tweaks.DebugLogger;
import eu.m724.tweaks.Language;
import org.bukkit.Location;
import org.bukkit.Material;
@ -65,7 +66,7 @@ public class RedstoneRepeaters {
repeatersById.put(repeaterId, block.getLocation());
block.setMetadata("rid", new FixedMetadataValue(plugin, repeaterId));
Store.getInstance().saveRepeaterData(block.getLocation(), repeaterId, (byte) 0);
RedstoneStore.getInstance().saveRepeaterData(block.getLocation(), repeaterId, (byte) 0);
return repeaterId;
}
@ -79,7 +80,7 @@ public class RedstoneRepeaters {
if (location == null) return;
repeatersByPower.remove(repeaterId);
Store.getInstance().deleteSavedRepeaterData(location);
RedstoneStore.getInstance().deleteSavedRepeaterData(location);
}
/* Get functions */
@ -89,7 +90,7 @@ public class RedstoneRepeaters {
// if not, we're not loading because it's loaded as the block is
var loc = repeatersById.get(repeaterId);
if (loc == null) {
System.err.println("Delete because no loc");
DebugLogger.fine("isValid: Delete because no loc");
delete(repeaterId);
return false;
}
@ -101,6 +102,7 @@ public class RedstoneRepeaters {
// check if the block is correct type
if (loc.getBlock().getType() != Material.DAYLIGHT_DETECTOR) {
DebugLogger.fine("isValid: Delete because not sensor");
delete(repeaterId);
return false;
}
@ -108,7 +110,7 @@ public class RedstoneRepeaters {
// check if the block has the same ID bound
var meta = loc.getBlock().getMetadata("rid");
if (meta.isEmpty() || meta.getFirst().asInt() != repeaterId) {
System.err.println("Delete because no meta");
DebugLogger.fine("isValid: Delete because no meta");
delete(repeaterId);
return false;
}
@ -126,7 +128,7 @@ public class RedstoneRepeaters {
if (id == null) {
// not in memory, check if repeater
var d = Store.getInstance().getSavedRepeaterData(block.getLocation());
var d = RedstoneStore.getInstance().getSavedRepeaterData(block.getLocation());
if (d == null) {
block.setMetadata("rid", new FixedMetadataValue(plugin, Integer.MIN_VALUE));
@ -153,12 +155,13 @@ public class RedstoneRepeaters {
var storedId = location.getBlock().getMetadata("rid").getFirst().asInt();
if (storedId != repeaterId) {
System.out.println("retrieved but not exitt");
DebugLogger.fine("attempted retrieve, but doesn't exist, deleting " + repeaterId);
delete(repeaterId);
return null;
}
System.out.println("retrieved exist " + repeaterId);
DebugLogger.fine("retrieved " + repeaterId);
return location.getBlock();
}
@ -170,20 +173,21 @@ public class RedstoneRepeaters {
block.getWorld().spawnParticle(Particle.LAVA, block.getLocation().add(0.5, 0.5, 0.5), 3);
System.out.println("Okay I got in power" + block.getBlockPower());
return (byte) block.getBlockPower();
var power = (byte) block.getBlockPower();
DebugLogger.fine("Got " + repeaterId + " receives " + power);
return power;
}
byte getOutboundPower(int repeaterId) {
var block = getBlock(repeaterId);
if (block == null) return -1;
System.out.println("Okay I got out power" + repeatersByPower.get(repeaterId));
return repeatersByPower.getOrDefault(repeaterId, (byte) 0);
var power = repeatersByPower.getOrDefault(repeaterId, (byte) 0);
DebugLogger.fine("Got " + repeaterId + " outputs " + power);
return power;
}
void setPower(int repeaterId, byte power) {
System.out.println(power);
if (power < 0 || power > 15)
throw new IllegalArgumentException("Power should be 0-15, but is " + power);
@ -197,6 +201,6 @@ public class RedstoneRepeaters {
block.getWorld().spawnParticle(Particle.LAVA, block.getLocation().add(0.5, 0.5, 0.5), 3);
System.out.println("Okay I set power");
DebugLogger.fine("Set power of " + repeaterId + " to " + power);
}
}

View file

@ -7,6 +7,7 @@
package eu.m724.tweaks.redstone;
import com.google.common.primitives.Ints;
import eu.m724.tweaks.DebugLogger;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
@ -15,23 +16,23 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class Store {
private static Store INSTANCE;
public class RedstoneStore {
private static RedstoneStore INSTANCE;
private final Plugin plugin;
private final File directory;
private Store(Plugin plugin) {
private RedstoneStore(Plugin plugin) {
this.plugin = plugin;
this.directory = new File(plugin.getDataFolder(), "storage/redstone");
directory.mkdirs();
}
static void init(Plugin plugin) {
INSTANCE = new Store(plugin);
INSTANCE = new RedstoneStore(plugin);
}
static Store getInstance() {
static RedstoneStore getInstance() {
return INSTANCE;
}
@ -51,12 +52,13 @@ public class Store {
var repeaterId = Ints.fromByteArray(bytes) & ~0xF;
var powerLevel = (byte) (bytes[3] & 0xF);
DebugLogger.fine("load " + location + " " + repeaterId + " " + powerLevel);
return Pair.of(repeaterId, powerLevel);
}
void saveRepeaterData(Location location, int repeaterId, byte powerLevel) {
var file = getFile(location);
System.out.println(file);
byte[] bytes = Ints.toByteArray((repeaterId & ~0xF) | (powerLevel & 0xF));
try {
@ -64,6 +66,8 @@ public class Store {
} catch (IOException e) {
throw new RuntimeException("Saving repeater data", e);
}
DebugLogger.fine("save " + location + " " + repeaterId + " " + powerLevel);
}
void deleteSavedRepeaterData(Location location) {

View file

@ -28,7 +28,7 @@ public class UpdaterManager {
public UpdaterManager(Plugin plugin) {
this.plugin = plugin;
cacheFile = new File(plugin.getDataFolder(), "cache/updater");
cacheFile = new File(plugin.getDataFolder(), "storage/updater");
}
public void init(PluginCommand updatesCommand){

View file

@ -120,4 +120,4 @@ knockback:
# Finally, thank you for downloading Tweaks724, I hope you enjoy!
# Don't modify unless told to
magic number don't modify this: 1
magic number don't modify this: 2

View file

@ -30,4 +30,6 @@ 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
authKickUnregistered = You are not whitelisted on this server!
retstoneBlockItem = Online redstone block
retstoneBlockItem = Online redstone block
clickToCopy = Click to copy to clipboard