Skip to content

Commit

Permalink
fix: polish code pattern in hologram classes
Browse files Browse the repository at this point in the history
* deleted useless import and debug logging

* refactor useless code pattern

* added more javadoc to some class
  • Loading branch information
tintinkung committed Apr 19, 2024
1 parent 86dd3e5 commit f0c1fc6
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 207 deletions.
238 changes: 95 additions & 143 deletions src/main/java/com/alpsbte/plotsystem/core/holograms/CountryBoard.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramDisplay;

import java.sql.SQLException;

public final class HologramRegister extends HologramManager {

public static void init() {
Expand All @@ -45,7 +43,7 @@ public LeaderboardPositionLine(int position, String username, int score) {

public static class CountryBoardPositionLine extends DecentHologramDisplay.TextLine {
public CountryBoardPositionLine(String id, String status, String difficulty) {
super(id + "§7 - " + (status != null ? "§a" + status : "§8No plot left") + " §7- " + (difficulty != null ? difficulty : "§8Unknown"));
super(id + "§7 - " + (status != null ? "§a" + status : "§8No plot left") + " §7- " + (difficulty != null ? difficulty : "§8Unknown"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

import java.util.List;
import java.util.UUID;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//


public interface DecentHologramContent {
ItemStack getItem();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.alpsbte.plotsystem.core.holograms.connector;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -14,25 +8,14 @@
import java.util.UUID;
import java.util.logging.Level;

// import com.alpsbte.alpslib.hologram.HolographicEventListener;
import com.alpsbte.plotsystem.core.system.tutorial.AbstractTutorialHologram;
import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.DecentHolograms;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import eu.decentsoftware.holograms.api.DecentHologramsAPI;
import eu.decentsoftware.holograms.api.holograms.HologramLine;
import eu.decentsoftware.holograms.api.holograms.HologramManager;

import eu.decentsoftware.holograms.api.holograms.HologramPage;


//import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
// import me.filoghost.holographicdisplays.api.Position;
//import me.filoghost.holographicdisplays.api.hologram.PlaceholderSetting;
//import me.filoghost.holographicdisplays.api.hologram.VisibilitySettings.Visibility;
//import me.filoghost.holographicdisplays.api.hologram.line.HologramLine;
//import me.filoghost.holographicdisplays.api.hologram.line.ItemHologramLine;
//import me.filoghost.holographicdisplays.api.hologram.line.TextHologramLine;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -70,14 +53,11 @@ public void create(Player player) {
if (this.holograms.containsKey(player.getUniqueId())) {
this.reload(player.getUniqueId());
} else {
HologramManager hologramManager = decentHolograms.getHologramManager();
hologramManager.updateVisibility(player);

Bukkit.getLogger().log(Level.INFO, "[DHAPI] Created display ID: " + id + " For player: " + player.getUniqueId());
Hologram hologram = DHAPI.createHologram(player.getUniqueId() + "-" + id, position);
// Allow only player to see
hologram.setDefaultVisibleState(false);
hologram.setShowPlayer(player);
Bukkit.getLogger().log(Level.INFO, "Creating a hologram: " + hologram + " of hologram: " + hologramManager.getHologram(player.getUniqueId().toString()));

this.holograms.put(player.getUniqueId(), hologram);
this.reload(player.getUniqueId());
Expand Down Expand Up @@ -166,11 +146,14 @@ public HashMap<UUID, Hologram> getHolograms() {
return this.holograms;
}

/**
* Write a hologram page by any DataLine of type
* @param page The hologram page to write
* @param startIndex Start line to update
* @param dataLines The data item to be write on the page
*/
protected static void updateDataLines(HologramPage page, int startIndex, List<DataLine<?>> dataLines) {
int index = startIndex;
Bukkit.getLogger().log(Level.INFO, "Updating dataline of: " + page + " with: " + dataLines);
Bukkit.getLogger().log(Level.INFO, "Looking for pages: " + page + " of line: " + page.getLines());

if (index == 0 && page.getLines().size() > dataLines.size()) {
int removeCount = page.getLines().size() - dataLines.size();

Expand All @@ -190,43 +173,43 @@ protected static void updateDataLines(HologramPage page, int startIndex, List<Da

}

/**
* Write an index line of a hologram page
* @param page The hologram page to write
* @param line The index line to write to
* @param item any minecraft item as an ItemStack to be inserted
*/
protected static void replaceLine(HologramPage page, int line, ItemStack item) {
Bukkit.getLogger().log(Level.INFO, "Replacing data item of: " + page.getLines().size() + " with: " + item);

if (page.getLines().size() < line + 1) {
Bukkit.getLogger().log(Level.INFO, "Inserting item 1: " + line);
DHAPI.addHologramLine(page, item);
} else {
Bukkit.getLogger().log(Level.INFO, "Inserting item 2: " + item);
HologramLine hologramLine = page.getLines().get(line);
if (hologramLine != null) {

DHAPI.insertHologramLine(page, line, item);
DHAPI.removeHologramLine(page, line + 1);
} else {
Bukkit.getLogger().log(Level.INFO, "Inserting item 3: " + line);
DHAPI.setHologramLine(page, line, item);

}
}
}

/**
* Write an index line of a hologram page
* @param page The hologram page to write
* @param line The index line to write to
* @param text The text to be written on
*/
protected static void replaceLine(HologramPage page, int line, String text) {
Bukkit.getLogger().log(Level.INFO, "Replacing dataline of: " + page.getLines().size() + " with: " + text);


if (page.getLines().size() < line + 1) {
Bukkit.getLogger().log(Level.INFO, "Inserting 1: " + line);
DHAPI.addHologramLine(page, text);
} else {
Bukkit.getLogger().log(Level.INFO, "Inserting 2: " + line);
HologramLine hologramLine = page.getLines().get(line);
if (hologramLine != null) {

DHAPI.insertHologramLine(page, line, text);
DHAPI.removeHologramLine(page, line + 1);
} else {
Bukkit.getLogger().log(Level.INFO, "Inserting 3: " + line);
DHAPI.setHologramLine(page, line, text);
}
}
Expand All @@ -237,7 +220,7 @@ public void setClickListener(@Nullable AbstractTutorialHologram.ClickAction clic
this.clickListener = clickListener;
}

public @Nullable AbstractTutorialHologram.ClickAction getClickListender() {
public @Nullable AbstractTutorialHologram.ClickAction getClickListener() {
return this.clickListener;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.alpsbte.plotsystem.core.holograms.connector;

import eu.decentsoftware.holograms.event.HologramClickEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
Expand Down Expand Up @@ -44,9 +43,9 @@ public void onPlayerChangedWorldEvent(PlayerChangedWorldEvent event) {
@EventHandler
public void onHologramClick(HologramClickEvent event) {
for (DecentHologramDisplay display : DecentHologramDisplay.activeDisplays) {
if (display.getLocation() == null | display.getClickListender() == null) continue;
if (display.getLocation() == null | display.getClickListener() == null) continue;
if (display.getHologram(event.getPlayer().getUniqueId()).equals(event.getHologram()))
display.getClickListender().onClick(event);
display.getClickListener().onClick(event);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import eu.decentsoftware.holograms.api.holograms.HologramManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -41,17 +40,13 @@ public void create(Player player) {
if (this.holograms.containsKey(player.getUniqueId())) {
this.reload(player.getUniqueId());
} else {
HologramManager hologramManager = decentHolograms.getHologramManager();
hologramManager.updateVisibility(player);

Bukkit.getLogger().log(Level.INFO, "[DHAPI] Created display ID: " + super.getId() + " For player: " + player.getUniqueId());
Hologram hologram = DHAPI.createHologram(player.getUniqueId() + "-" + super.getId(), super.getLocation());
for(int i = 1; i <= pageCount; i++) hologram.addPage();

// Allow only player to see
hologram.setDefaultVisibleState(false);
hologram.setShowPlayer(player);
Bukkit.getLogger().log(Level.INFO, "Creating a hologram: " + hologram + " of hologram: " + hologramManager.getHologram(player.getUniqueId().toString()));

this.holograms.put(player.getUniqueId(), hologram);
this.reload(player.getUniqueId());
}
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/com/alpsbte/plotsystem/core/system/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,20 @@ public static int getBuilderScore(UUID uuid, ScoreLeaderboard.LeaderboardTimefra
}

/**
*
* @return
* @throws SQLException
* Select both country and city entries as ID and name, intersect with city ID ordered by country ID
* <pre>
* {@code
* SELECT countries.id AS country_id, countries.name AS country_name, city_projects.id AS project_id, city_projects.name AS project_name FROM plotsystem_countries AS countries
* FROM plotsystem_countries AS countries
* LEFT JOIN plotsystem_city_projects AS city_projects ON countries.id = city_projects.country_id
* ORDER BY country_id
* }</pre> SQL Query statement
* @return A List of every registered city project data as a pair of country entry and city entry.
* @throws SQLException If Database connection is lost
*/
public static ArrayList<DatabaseEntry<DatabaseEntry<Integer, String>, DatabaseEntry<Integer, String>>> getProjectsSorted() throws SQLException {
public static ArrayList<DatabaseEntry<DatabaseEntry<Integer, String>,
DatabaseEntry<Integer, String>>> getProjectsSorted() throws SQLException
{
String query = "SELECT countries.id AS country_id, "
+ "countries.name AS country_name, "
+ "city_projects.id AS project_id, "
Expand All @@ -297,15 +306,14 @@ public static ArrayList<DatabaseEntry<DatabaseEntry<Integer, String>, DatabaseEn
+ "ORDER BY country_id";

try(ResultSet rs = DatabaseConnection.createStatement(query).executeQuery()) {
ArrayList<DatabaseEntry<DatabaseEntry<Integer, String>, DatabaseEntry<Integer, String>>> result = new ArrayList<>();

ArrayList<DatabaseEntry<DatabaseEntry<Integer, String>,
DatabaseEntry<Integer, String>>> result = new ArrayList<>();
while(rs.next()) {
result.add(new DatabaseEntry<>(
new DatabaseEntry<>(rs.getInt("country_id"), rs.getString("country_name")),
new DatabaseEntry<>(rs.getInt("project_id"), rs.getString("project_name"))
));
}

DatabaseConnection.closeResultSet(rs);
return result;
}
Expand All @@ -324,9 +332,9 @@ public static ArrayList<DatabaseEntry<DatabaseEntry<Integer, String>, DatabaseEn
* @return A List of every City ID containing a List of all plot entries in the city project.
* @throws SQLException If Database connection is lost
*/
public static ArrayList<DatabaseEntry<Integer,
ArrayList<DatabaseEntry<Integer,
DatabaseEntry<String, String>>>>> getPlotsSorted() throws SQLException {
public static ArrayList<DatabaseEntry<Integer, ArrayList<DatabaseEntry<Integer,
DatabaseEntry<String, String>>>>> getPlotsSorted() throws SQLException
{
String query = "SELECT city_projects.id AS city_id, "
+ "plots.status, plots.id, plots.difficulty_id AS difficulty_id, "
+ "difficulties.name AS difficulty "
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/alpsbte/plotsystem/utils/io/LangPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ public static final class WelcomeMessage {
public static final String WELCOME_BEDROCK2 = WELCOME + "bedrock-message-2";
}

public static final class CountryBoard {
private static final String CB = "country-board.";
public static final String TITLE = CB + "title";
public static final String HEADER_ID= CB + "header.id";
public static final String HEADER_STATUS = CB + "header.status";
public static final String HEADER_DIFFICULTY = CB + "header.difficulty";
public static final String FOOTER = CB + "footer";
}

public static final class Leaderboards {
private static final String LBS = "leaderboards.";
public static final String PAGES = LBS + "pages.";
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/lang/en_GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ welcome-message:
java-message-2: "§7Look up our §9Discord Server§r%newline%§7to get help from our staff."
bedrock-message-1: "Look at the §bCountry Board§r on the left to see all of our available plots."
bedrock-message-2: "Using §9plot ID§r from the board, you may use the command §e/plot create §e<§9ID§r§e>§r and start creating your first build!"
country-board:
title: "COUNTRY BOARD"
header:
id: "ID"
status: "Status"
difficulty: "Difficulty"
footer: "click to swap pages"
leaderboards:
pages:
DAILY: "Daily"
Expand Down

0 comments on commit f0c1fc6

Please sign in to comment.