did more of something

This commit is contained in:
LunarAkai 2024-07-17 14:20:24 +02:00
commit cd70a08b1f
11 changed files with 296 additions and 26 deletions

View file

@ -12,7 +12,7 @@
<name>BlockFox</name> <name>BlockFox</name>
<properties> <properties>
<java.version>1.8</java.version> <java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

View file

@ -1,15 +1,45 @@
package de.lunarakai.blockfox; package de.lunarakai.blockfox;
import de.iani.cubesideutils.bukkit.commands.CommandRouter; import de.iani.cubesideutils.bukkit.commands.CommandRouter;
import de.lunarakai.blockfox.commands.InfoCommand;
import de.lunarakai.blockfox.commands.TestRSSCommand; import de.lunarakai.blockfox.commands.TestRSSCommand;
import de.lunarakai.blockfox.common.BlockFoxManager;
import de.lunarakai.blockfox.common.DisplayList;
import java.util.Locale;
import java.util.ResourceBundle;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.translation.GlobalTranslator;
import net.kyori.adventure.translation.TranslationRegistry;
import net.kyori.adventure.util.UTF8ResourceBundleControl;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public final class BlockFoxPlugin extends JavaPlugin { public final class BlockFoxPlugin extends JavaPlugin {
public static final String PERMISSION_USE = "blockfox.use";
public static final String PERMISSION_ADMIN = "blockfox.admin";
private BlockFoxManager blockFoxManager;
private DisplayList displayList;
@Override @Override
public void onEnable() { public void onEnable() {
this.saveDefaultConfig(); this.saveDefaultConfig();
registerLocales();
getServer().getScheduler().runTask(this, this::onLateEnable);
}
public void onLateEnable() {
displayList = new DisplayList(this);
displayList.load();
blockFoxManager = new BlockFoxManager(this);
// Commands
CommandRouter commandRouter = new CommandRouter(getCommand("blockfox")); CommandRouter commandRouter = new CommandRouter(getCommand("blockfox"));
// Common
commandRouter.addCommandMapping(new InfoCommand(this), "info");
// RSS
commandRouter.addCommandMapping(new TestRSSCommand(this), "testrss"); commandRouter.addCommandMapping(new TestRSSCommand(this), "testrss");
} }
@ -18,4 +48,25 @@ public final class BlockFoxPlugin extends JavaPlugin {
public void onDisable() { public void onDisable() {
// Plugin shutdown logic // Plugin shutdown logic
} }
public DisplayList getDisplayList() {
return displayList;
}
public BlockFoxManager getManager() {
return blockFoxManager;
}
private void registerLocales() {
TranslationRegistry registry = TranslationRegistry.create(Key.key("blockfox:lang"));
ResourceBundle bundle_en_US = ResourceBundle.getBundle("lang.en_US", Locale.US, UTF8ResourceBundleControl.get());
registry.registerAll(Locale.US, bundle_en_US, true);
ResourceBundle bundle_de_DE = ResourceBundle.getBundle("lang.de_DE", Locale.GERMAN, UTF8ResourceBundleControl.get());
registry.registerAll(Locale.GERMAN, bundle_de_DE, true);
GlobalTranslator.translator().addSource(registry);
}
} }

View file

@ -0,0 +1,63 @@
package de.lunarakai.blockfox.commands;
import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.bukkit.commands.exceptions.DisallowsCommandBlockException;
import de.iani.cubesideutils.bukkit.commands.exceptions.IllegalSyntaxException;
import de.iani.cubesideutils.bukkit.commands.exceptions.InternalCommandException;
import de.iani.cubesideutils.bukkit.commands.exceptions.NoPermissionException;
import de.iani.cubesideutils.bukkit.commands.exceptions.RequiresPlayerException;
import de.iani.cubesideutils.commands.ArgsParser;
import de.lunarakai.blockfox.BlockFoxPlugin;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class InfoCommand extends SubCommand {
BlockFoxPlugin plugin;
public InfoCommand(BlockFoxPlugin plugin) {
this.plugin = plugin;
}
@Override
public String getUsage() {
return "";
}
@Override
public boolean requiresPlayer() {
return false;
}
@Override
public String getRequiredPermission() {
return BlockFoxPlugin.PERMISSION_USE;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String s1, ArgsParser args) throws DisallowsCommandBlockException, RequiresPlayerException, NoPermissionException, IllegalSyntaxException, InternalCommandException {
sender.sendMessage(Component.text("--- ", NamedTextColor.AQUA)
.append(Component.text(plugin.getName(), NamedTextColor.GREEN))
.append(Component.text(" ---", NamedTextColor.AQUA)));
sender.sendMessage(Component.translatable("blockfox.info.version", NamedTextColor.AQUA)
.append(Component.text(": ", NamedTextColor.AQUA))
.append(Component.text(plugin.getPluginMeta().getVersion(), NamedTextColor.GREEN)));
sender.sendMessage(Component.translatable("blockfox.info.developer", NamedTextColor.AQUA)
.append(Component.text(": ", NamedTextColor.AQUA))
.append(Component.text(plugin.getPluginMeta().getAuthors().getFirst(), NamedTextColor.GREEN)));
sender.sendMessage(Component.translatable("blockfox.info.website", NamedTextColor.AQUA)
.append(Component.text(": ", NamedTextColor.AQUA))
.append(Component.text(plugin.getPluginMeta().getWebsite(), NamedTextColor.GREEN)));
sender.sendMessage(Component.translatable("blockfox.info.license", NamedTextColor.AQUA)
.append(Component.text(": ", NamedTextColor.AQUA))
.append(Component.text("GPL-3.0", NamedTextColor.GREEN)));
return true;
}
}

View file

@ -2,6 +2,9 @@ package de.lunarakai.blockfox.common;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import de.lunarakai.blockfox.BlockFoxPlugin; import de.lunarakai.blockfox.BlockFoxPlugin;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Location; import org.bukkit.Location;
@ -17,14 +20,19 @@ public class BlockFoxDisplay {
private final BlockFace orientation; private final BlockFace orientation;
private DisplayStatus displayStatus = DisplayStatus.INACTIVE; private DisplayStatus displayStatus = DisplayStatus.INACTIVE;
private BlockFoxDisplayMode blockFoxDisplayMode = BlockFoxDisplayMode.RSS_FEED; private BlockFoxDisplayMode blockFoxDisplayMode = BlockFoxDisplayMode.RSS_FEED;
private ArrayList<URI> savedLinks;
private UUID[] textDisplays; private UUID[] textDisplays;
private Player currentPlayer; private Player currentPlayer;
// Width = 5
// Height = 3
public BlockFoxDisplay(BlockFoxPlugin plugin, ConfigurationSection displaySection) { public BlockFoxDisplay(BlockFoxPlugin plugin, ConfigurationSection displaySection) {
this.plugin = plugin; this.plugin = plugin;
this.name = Preconditions.checkNotNull(displaySection.getString("name")); this.name = Preconditions.checkNotNull(displaySection.getString("name"));
this.location = Preconditions.checkNotNull(displaySection.getLocation("location")); this.location = Preconditions.checkNotNull(displaySection.getLocation("location"));
this.textDisplays = new UUID[99]; // TODO this.textDisplays = new UUID[99]; // TODO
this.savedLinks = new ArrayList<>();
BlockFace orientation = BlockFace.NORTH; BlockFace orientation = BlockFace.NORTH;
try { try {
@ -38,7 +46,9 @@ public class BlockFoxDisplay {
String modeValue = displaySection.getString("mode"); String modeValue = displaySection.getString("mode");
switch(modeValue) { switch(modeValue) {
case "fixed_rss": this.blockFoxDisplayMode = BlockFoxDisplayMode.FIXED_RSS_FEED; break;
case "fediverse": this.blockFoxDisplayMode = BlockFoxDisplayMode.FEDIVERSE_CLIENT; break; case "fediverse": this.blockFoxDisplayMode = BlockFoxDisplayMode.FEDIVERSE_CLIENT; break;
case "fixed_fediverse": this.blockFoxDisplayMode = BlockFoxDisplayMode.FIXED_FEDIVERSE_CLIENT; break;
default: this.blockFoxDisplayMode = BlockFoxDisplayMode.RSS_FEED; default: this.blockFoxDisplayMode = BlockFoxDisplayMode.RSS_FEED;
} }
@ -49,7 +59,99 @@ public class BlockFoxDisplay {
textDisplays[i] = UUID.fromString(textDisplay); textDisplays[i] = UUID.fromString(textDisplay);
} }
} }
List<String> savedLinksList = displaySection.getStringList("savedlinks");
for(int i = 0; i < savedLinksList.size(); i++) {
String link = savedLinksList.get(i);
if(link != null) {
try {
URI uri = new URI(savedLinksList.get(i));
savedLinks.add(uri);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}
} }
public void save(ConfigurationSection displaySection) {
displaySection.set("name", name);
displaySection.set("location", location);
displaySection.set("orientation", orientation.name());
displaySection.set("mode", blockFoxDisplayMode.getModeName());
List<String> textDisplays = new ArrayList<>();
for(UUID uuid : this.textDisplays) {
textDisplays.add(uuid == null ? null : uuid.toString());
}
displaySection.set("textdisplays", textDisplays);
List<String> savedLinks = new ArrayList<>();
for(URI url : this.savedLinks) {
savedLinks.add(url == null ? null : url.toString());
}
displaySection.set("savedlinks", savedLinks);
}
public void addJoiningPlayer(Player player) {
Preconditions.checkNotNull(player);
Preconditions.checkState(displayStatus == DisplayStatus.INACTIVE);
this.displayStatus = DisplayStatus.ACTIVE;
this.currentPlayer = player;
}
public String getName() {
return name;
}
public boolean hasPlayer() {
return currentPlayer != null;
}
public Player getCurrentPlayer() {
return currentPlayer;
}
public Location getLocation() {
return location;
}
public BlockFace getOrientation() {
return orientation;
}
public DisplayStatus getDisplayStatus() {
return displayStatus;
}
public UUID[] getTextDisplays() {
return textDisplays;
}
public BlockFoxDisplayMode getBlockFoxDisplayMode() {
return blockFoxDisplayMode;
}
public void setDisplayStatus(DisplayStatus status) {
this.displayStatus = status;
}
public void setBlockFoxDisplayMode(BlockFoxDisplayMode mode) {
this.blockFoxDisplayMode = mode;
}
public ArrayList<URI> getSavedLinks() {
return savedLinks;
}
public void addLink(URI link) {
savedLinks.add(link);
}
private int getRotationYaw() {
return switch (orientation) {
case EAST -> 90;
case SOUTH -> 180;
case WEST -> 270;
default -> 0;
};
}
} }

View file

@ -1,6 +1,18 @@
package de.lunarakai.blockfox.common; package de.lunarakai.blockfox.common;
public enum BlockFoxDisplayMode { public enum BlockFoxDisplayMode {
RSS_FEED, RSS_FEED ("rss"),
FEDIVERSE_CLIENT FIXED_RSS_FEED ("fixed_rss"),
} FEDIVERSE_CLIENT ("fediverse"),
FIXED_FEDIVERSE_CLIENT ("fixed_fediverse");
private final String name;
BlockFoxDisplayMode(String mode) {
name = mode;
}
public String getModeName() {
return this.name;
}
}

View file

@ -1,4 +1,32 @@
package de.lunarakai.blockfox.common; package de.lunarakai.blockfox.common;
import com.google.common.base.Preconditions;
import de.lunarakai.blockfox.BlockFoxPlugin;
import de.lunarakai.lunarutils.chat.MessageUtils;
import org.bukkit.entity.Player;
public class BlockFoxManager { public class BlockFoxManager {
private final BlockFoxPlugin plugin;
public BlockFoxManager(BlockFoxPlugin plugin) {
this.plugin = plugin;
}
public void joinDisplay(Player player, BlockFoxDisplay display) {
if(!player.hasPermission(BlockFoxPlugin.PERMISSION_USE)) {
return;
}
Preconditions.checkArgument(plugin.getDisplayList().getPlayerDisplay(player) == null, "player is already using a display");
Preconditions.checkArgument(display.getDisplayStatus() == DisplayStatus.INACTIVE, "display is already in use");
display.addJoiningPlayer(player);
plugin.getDisplayList().setBlockFoxDisplayForPlayer(player, display);
}
public void leaveDisplay(Player player, boolean message) {
BlockFoxDisplay display = plugin.getDisplayList().getPlayerDisplay(player);
Preconditions.checkArgument(display != null, "player is not using any display");
plugin.getDisplayList().setBlockFoxDisplayForPlayer(player, null);
if(message) {
MessageUtils.sendSimpleInfoMessage(player, "blockfox.display.usagecanceled");
}
}
} }

View file

@ -76,10 +76,10 @@ public class DisplayList {
} }
private void setDisplayBlocks(BlockFoxDisplay blockFoxDisplay) { private void setDisplayBlocks(BlockFoxDisplay blockFoxDisplay) {
for(Location loc : blockFoxDisplay.getBlocks()) { // for(Location loc : blockFoxDisplay.getBlocks()) {
bfdisplayBlocks.put(loc.clone(), blockFoxDisplay); // bfdisplayBlocks.put(loc.clone(), blockFoxDisplay);
} // }
for(UUID uuid : blockFoxDisplay.getItemDisplays()) { for(UUID uuid : blockFoxDisplay.getTextDisplays()) {
if(uuid != null) { if(uuid != null) {
bfdisplayItemDisplays.put(uuid, blockFoxDisplay); bfdisplayItemDisplays.put(uuid, blockFoxDisplay);
} }
@ -101,11 +101,11 @@ public class DisplayList {
} }
public boolean collidesWithBlockFoxDisplay(BlockFoxDisplay newBlockFoxDisplay) { public boolean collidesWithBlockFoxDisplay(BlockFoxDisplay newBlockFoxDisplay) {
for(Location location : newBlockFoxDisplay.getBlocks()) { // for(Location location : newBlockFoxDisplay.getBlocks()) {
if(bfdisplayBlocks.get(location) != null) { // if(bfdisplayBlocks.get(location) != null) {
return true; // return true;
} // }
} // }
return false; return false;
} }
@ -131,18 +131,18 @@ public class DisplayList {
public void removeBlockFoxDisplay(BlockFoxDisplay blockFoxDisplay) { public void removeBlockFoxDisplay(BlockFoxDisplay blockFoxDisplay) {
if(blockFoxDisplay.hasPlayer()) { if(blockFoxDisplay.hasPlayer()) {
plugin.getManager().quitDisplay(blockFoxDisplay.getCurrentPlayer(), true, true); plugin.getManager().leaveDisplay(blockFoxDisplay.getCurrentPlayer(), true);
} }
for(UUID uuid : arena.getItemDisplays()) { for(UUID uuid : blockFoxDisplay.getTextDisplays()) {
if(uuid != null) { if(uuid != null) {
bfdisplayItemDisplays.remove(uuid); bfdisplayItemDisplays.remove(uuid);
} }
} }
for(Location block : blockFoxDisplay.getBlocks()) { // for(Location block : blockFoxDisplay.getBlocks()) {
bfdisplayBlocks.remove(block); // bfdisplayBlocks.remove(block);
} // }
blockFoxDisplay.removeItemDisplay(); //blockFoxDisplay.removeItemDisplay();
bfDisplays.remove(blockFoxDisplay.getName()); bfDisplays.remove(blockFoxDisplay.getName());
save(); save();

View file

@ -8,8 +8,7 @@ import org.jsoup.select.Elements;
public class HTMLUtils { public class HTMLUtils {
public static List<String> formatHTMLList(Document document) { public static List<String> formatHTMLList(Document document) {
// todo: format html elements to readable string (for example new line at ul li) // Todo: needs a prettier solution but it works for one sub list point at least ^^
// todo: with current method ul li inside another ul li are duplicated
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
Elements elements = document.select("ul"); Elements elements = document.select("ul");
Elements li = elements.select("li"); Elements li = elements.select("li");
@ -20,10 +19,6 @@ public class HTMLUtils {
continue; continue;
} }
list.add("- " + element.text() + "\n"); list.add("- " + element.text() + "\n");
} }
return list; return list;
} }

View file

@ -0,0 +1,6 @@
blockfox.info.version=Version
blockfox.info.developer=Entwickelt von
blockfox.info.website=Website
blockfox.info.license=Lizenz
blockfox.display.usagecanceled="Die Benutzung wurde abgebrochen"

View file

@ -0,0 +1,7 @@
# Info Command
blockfox.info.version=Version
blockfox.info.developer=Developed by
blockfox.info.website=Website
blockfox.info.license=License
blockfox.display.usagecanceled=The usage was canceled

View file

@ -1,10 +1,16 @@
name: BlockFox name: BlockFox
version: '${project.version}' version: '${project.version}'
main: de.lunarakai.blockfox.BlockFoxPlugin main: de.lunarakai.blockfox.BlockFoxPlugin
author: LunarAkai
website: https://github.com/LunarAkai/BlockFox
api-version: '1.21' api-version: '1.21'
depend: depend:
- CubesideUtils - CubesideUtils
- LunarUtils - LunarUtils
commands: commands:
blockfox: blockfox:
description: main command description: main command
permissions:
blockfox.admin: {}
blockfox.use: {}