mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
add display name command and don't use middle click because mojang broke it lol
This commit is contained in:
@@ -16,6 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -77,7 +78,7 @@ public class ArenaCommand implements CommandExecutor {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
boolean success = dao.newArena(new Arena(arenaName, player.getLocation(), icon));
|
||||
boolean success = dao.newArena(new Arena(arenaName, null, player.getLocation(), icon));
|
||||
if (success) {
|
||||
player.sendMessage(Component.text("Created arena", NamedTextColor.GREEN));
|
||||
} else {
|
||||
@@ -105,6 +106,26 @@ public class ArenaCommand implements CommandExecutor {
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else if (args.length > 0 && args[0].equalsIgnoreCase("displayname")) {
|
||||
if (args.length < 3) {
|
||||
return false;
|
||||
}
|
||||
if (!player.hasPermission("kitpvp.admin")) {
|
||||
player.sendMessage(Component.text("No permission", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
String arenaName = args[1];
|
||||
String displayName = String.join(" ", Arrays.copyOfRange(args, 2, args.length));
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
boolean success = dao.setDisplayName(arenaName, displayName);
|
||||
if (success) {
|
||||
player.sendMessage(Component.text("Set display name of arena", NamedTextColor.GREEN));
|
||||
} else {
|
||||
player.sendMessage(Component.text("Could not set display name of arena. Does it exist?", NamedTextColor.RED));
|
||||
}
|
||||
});
|
||||
} else if (args.length == 0) {
|
||||
new ArenaGui(dao, manager).open(player);
|
||||
return true;
|
||||
|
||||
@@ -5,8 +5,11 @@ import org.bukkit.Material;
|
||||
|
||||
public record Arena(
|
||||
String name,
|
||||
String displayName,
|
||||
Location spawn,
|
||||
Material icon
|
||||
) {
|
||||
|
||||
public String displayName() {
|
||||
return this.displayName == null ? this.name : this.displayName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,6 @@ public interface ArenaDao {
|
||||
boolean newArena(Arena arena);
|
||||
|
||||
boolean deleteArena(String arenaName);
|
||||
|
||||
boolean setDisplayName(String arenaName, String displayName);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ public class SqlArenaDao implements ArenaDao {
|
||||
PRIMARY KEY (name)
|
||||
)
|
||||
""");
|
||||
source.registerMigration(5, false,
|
||||
"""
|
||||
ALTER TABLE arenas ADD COLUMN IF NOT EXISTS display_name VARCHAR(64)
|
||||
""");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,6 +46,7 @@ public class SqlArenaDao implements ArenaDao {
|
||||
while (resultSet.next()) {
|
||||
arenas.add(new Arena(
|
||||
resultSet.getString("name"),
|
||||
resultSet.getString("display_name"),
|
||||
new Location(null, resultSet.getDouble("spawn_x"), resultSet.getDouble("spawn_y"), resultSet.getDouble("spawn_z"), resultSet.getFloat("spawn_yaw"), 0),
|
||||
Material.valueOf(resultSet.getString("icon"))
|
||||
));
|
||||
@@ -83,4 +88,18 @@ public class SqlArenaDao implements ArenaDao {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDisplayName(String arenaName, String displayName) {
|
||||
try (Connection connection = source.getConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement("UPDATE arenas SET display_name = ? WHERE name = ?");
|
||||
statement.setString(1, displayName);
|
||||
statement.setString(2, arenaName);
|
||||
|
||||
return statement.executeUpdate() == 1;
|
||||
} catch (SQLException ex) {
|
||||
JavaPlugin.getPlugin(KitPvpPlugin.class).getLogger().log(Level.WARNING, "Error setting display name of arena", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ public class ArenaGui {
|
||||
if (isOwner) {
|
||||
meta.setEnchantmentGlintOverride(true);
|
||||
}
|
||||
meta.itemName(Component.text(arena.name(), NamedTextColor.WHITE));
|
||||
meta.itemName(Component.text(arena.displayName(), NamedTextColor.LIGHT_PURPLE));
|
||||
|
||||
List<Component> lore = new ArrayList<>();
|
||||
lore.add(Component.text("Created by " + loadedArena.owner().getName(), NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false));
|
||||
lore.add(Component.text("Click to teleport", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false));
|
||||
if (hasAccess) {
|
||||
lore.add(Component.text("Middle click to delete", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false));
|
||||
lore.add(Component.text("Shift right click to delete", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false));
|
||||
}
|
||||
World world = Bukkit.getWorld(manager.getArenaName(arena.name(), loadedArena.owner()));
|
||||
if (world != null && world.getPlayerCount() > 0) {
|
||||
@@ -79,9 +79,9 @@ public class ArenaGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMiddleClick(@NotNull Player clicker) {
|
||||
protected void onShiftRightClick(@NotNull Player clicker) {
|
||||
if (!hasAccess) {
|
||||
super.onMiddleClick(clicker);
|
||||
super.onShiftRightClick(clicker);
|
||||
}
|
||||
|
||||
new ConfirmDeletionGui(manager, loadedArena.owner(), clicker);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ArenaSelectionGui {
|
||||
for (Arena arena : arenaDao.getArenas()) {
|
||||
ItemStack item = new ItemStack(arena.icon());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.itemName(Component.text(arena.name(), NamedTextColor.WHITE));
|
||||
meta.itemName(Component.text(arena.displayName(), NamedTextColor.LIGHT_PURPLE));
|
||||
item.setItemMeta(meta);
|
||||
inventory.setSlot(new Clickable(item) {
|
||||
@Override
|
||||
|
||||
@@ -186,7 +186,7 @@ public class KitListGui {
|
||||
iconMeta.lore(List.of(
|
||||
Component.text("Left click to load", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false),
|
||||
Component.text("Right click to edit", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false),
|
||||
Component.text("Middle click to delete", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false)
|
||||
Component.text("Shift right click to delete", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false)
|
||||
));
|
||||
icon.setItemMeta(iconMeta);
|
||||
clickables.add(new Clickable(icon) {
|
||||
@@ -202,7 +202,7 @@ public class KitListGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMiddleClick(@NotNull Player clicker) {
|
||||
protected void onShiftRightClick(@NotNull Player clicker) {
|
||||
new ConfirmDeletionGui(KitListGui.this.dao, clicker, kit, KitListGui.this.view);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ public class DatabaseManager {
|
||||
}
|
||||
|
||||
private void initialiseTables() {
|
||||
dataSource.registerMigration(2, false, """
|
||||
dataSource.registerMigration(4, false, """
|
||||
CREATE TABLE IF NOT EXISTS warps (
|
||||
name VARCHAR(64) PRIMARY KEY,
|
||||
world VARCHAR(64) NOT NULL,
|
||||
|
||||
@@ -20,6 +20,7 @@ commands:
|
||||
/<command> list
|
||||
/<command> create <name> <icon> (administrators only)
|
||||
/<command> delete <name> (administrators only)
|
||||
/<command> displayname <name> <display name> (administrators only)
|
||||
spawn: {}
|
||||
setspawn:
|
||||
permission: kitpvp.admin
|
||||
|
||||
Reference in New Issue
Block a user