some more shit
This commit is contained in:
parent
4e54849ae4
commit
002b05820e
@ -23,21 +23,31 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="998d5e92-ac1f-4423-8aef-5f389ab213de" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/BaseCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/AddCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/LevelCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/RemoveCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/SetCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/setspawn/SetSpawnCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/setspawn/SpawnCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/AddCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/RemoveCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/SetCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/XpCommand.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/listeners/RandomListeners.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/managers/CommandManager.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/Assemble.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/AssembleAdapter.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/AssembleBoard.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/AssembleBoardEntry.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/AssembleException.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/AssembleListener.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/AssembleStyle.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/AssembleThread.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/events/AssembleBoardCreateEvent.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/events/AssembleBoardCreatedEvent.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/assemble/events/AssembleBoardDestroyEvent.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/managers/ScoreboardManager.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/BedWars.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/BedWars.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/LevelCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/LevelCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/RemoveCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/RemoveCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/SetCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/SetCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/setspawn/SpawnCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/setspawn/SpawnCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/AddCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/AddCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/RemoveCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/RemoveCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/SetCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/SetCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/XpCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/XpCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/managers/CommandManager.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/managers/CommandManager.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerData.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerData.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerDataManager.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerDataManager.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/resources/plugin.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/plugin.yml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -71,7 +81,7 @@
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/main/java" />
|
||||
<property name="settings.editor.selected.configurable" value="MTConfigurable" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
@ -80,6 +90,7 @@
|
||||
<recent name="rip.tilly.bedwars.utils" />
|
||||
</key>
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\logan\Documents\GitHub\BedWars\src\main\java" />
|
||||
<recent name="C:\Users\logan\Documents\GitHub\BedWars\src\main\java\rip\tilly\bedwars\commands" />
|
||||
<recent name="C:\Users\Luca\Documents\GitHub\BedWars\src\main\java\rip\tilly\bedwars" />
|
||||
</key>
|
||||
@ -166,4 +177,14 @@
|
||||
</option>
|
||||
<option name="oldMeFiltersMigrated" value="true" />
|
||||
</component>
|
||||
<component name="WindowStateProjectService">
|
||||
<state x="574" y="115" key="#com.intellij.ide.util.MemberChooser" timestamp="1637507010776">
|
||||
<screen x="0" y="0" width="1536" height="824" />
|
||||
</state>
|
||||
<state x="574" y="115" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824/1920.0.800.560@0.0.1536.824" timestamp="1637507010776" />
|
||||
<state x="499" y="159" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1637505947686">
|
||||
<screen x="0" y="0" width="1536" height="824" />
|
||||
</state>
|
||||
<state x="499" y="159" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1536.824/1920.0.800.560@0.0.1536.824" timestamp="1637505947686" />
|
||||
</component>
|
||||
</project>
|
108
src/main/java/assemble/Assemble.java
Normal file
108
src/main/java/assemble/Assemble.java
Normal file
@ -0,0 +1,108 @@
|
||||
package assemble;
|
||||
|
||||
import assemble.events.AssembleBoardCreateEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Getter @Setter
|
||||
public class Assemble {
|
||||
|
||||
private JavaPlugin plugin;
|
||||
|
||||
private AssembleAdapter adapter;
|
||||
private AssembleThread thread;
|
||||
private AssembleListener listeners;
|
||||
private AssembleStyle assembleStyle = AssembleStyle.MODERN;
|
||||
|
||||
private Map<UUID, AssembleBoard> boards;
|
||||
|
||||
private long ticks = 2;
|
||||
private boolean hook = false, debugMode = true;
|
||||
|
||||
/**
|
||||
* Assemble.
|
||||
*
|
||||
* @param plugin instance.
|
||||
* @param adapter
|
||||
*/
|
||||
public Assemble(JavaPlugin plugin, AssembleAdapter adapter) {
|
||||
if (plugin == null) {
|
||||
throw new RuntimeException("Assemble can not be instantiated without a plugin instance!");
|
||||
}
|
||||
|
||||
this.plugin = plugin;
|
||||
this.adapter = adapter;
|
||||
this.boards = new ConcurrentHashMap<>();
|
||||
|
||||
this.setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup Assemble.
|
||||
*/
|
||||
public void setup() {
|
||||
// Register Events.
|
||||
this.listeners = new AssembleListener(this);
|
||||
this.plugin.getServer().getPluginManager().registerEvents(listeners, this.plugin);
|
||||
|
||||
// Ensure that the thread has stopped running.
|
||||
if (this.thread != null) {
|
||||
this.thread.stop();
|
||||
this.thread = null;
|
||||
}
|
||||
|
||||
// Register new boards for existing online players.
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// Make sure it doesn't double up.
|
||||
AssembleBoardCreateEvent createEvent = new AssembleBoardCreateEvent(player);
|
||||
|
||||
Bukkit.getPluginManager().callEvent(createEvent);
|
||||
if (createEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getBoards().putIfAbsent(player.getUniqueId(), new AssembleBoard(player, this));
|
||||
}
|
||||
|
||||
// Start Thread.
|
||||
this.thread = new AssembleThread(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void cleanup() {
|
||||
// Stop thread.
|
||||
if (this.thread != null) {
|
||||
this.thread.stop();
|
||||
this.thread = null;
|
||||
}
|
||||
|
||||
// Unregister listeners.
|
||||
if (listeners != null) {
|
||||
HandlerList.unregisterAll(listeners);
|
||||
listeners = null;
|
||||
}
|
||||
|
||||
// Destroy player scoreboards.
|
||||
for (UUID uuid : getBoards().keySet()) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null || !player.isOnline()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
getBoards().remove(uuid);
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
25
src/main/java/assemble/AssembleAdapter.java
Normal file
25
src/main/java/assemble/AssembleAdapter.java
Normal file
@ -0,0 +1,25 @@
|
||||
package assemble;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AssembleAdapter {
|
||||
|
||||
/**
|
||||
* Get's the scoreboard title.
|
||||
*
|
||||
* @param player who's title is being displayed.
|
||||
* @return title.
|
||||
*/
|
||||
String getTitle(Player player);
|
||||
|
||||
/**
|
||||
* Get's the scoreboard lines.
|
||||
*
|
||||
* @param player who's lines are being displayed.
|
||||
* @return lines.
|
||||
*/
|
||||
List<String> getLines(Player player);
|
||||
|
||||
}
|
127
src/main/java/assemble/AssembleBoard.java
Normal file
127
src/main/java/assemble/AssembleBoard.java
Normal file
@ -0,0 +1,127 @@
|
||||
package assemble;
|
||||
|
||||
import assemble.events.AssembleBoardCreatedEvent;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AssembleBoard {
|
||||
|
||||
@Getter private Assemble assemble;
|
||||
|
||||
@Getter private final List<AssembleBoardEntry> entries = new ArrayList<>();
|
||||
@Getter private final List<String> identifiers = new ArrayList<>();
|
||||
|
||||
@Getter private final UUID uuid;
|
||||
|
||||
/**
|
||||
* Assemble Board.
|
||||
*
|
||||
* @param player that the board belongs to.
|
||||
* @param assemble instance.
|
||||
*/
|
||||
public AssembleBoard(Player player, Assemble assemble) {
|
||||
this.uuid = player.getUniqueId();
|
||||
this.assemble = assemble;
|
||||
this.setup(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's a player's bukkit scoreboard.
|
||||
*
|
||||
* @return either existing scoreboard or new scoreboard.
|
||||
*/
|
||||
public Scoreboard getScoreboard() {
|
||||
Player player = Bukkit.getPlayer(getUuid());
|
||||
if (getAssemble().isHook() || player.getScoreboard() != Bukkit.getScoreboardManager().getMainScoreboard()) {
|
||||
return player.getScoreboard();
|
||||
} else {
|
||||
return Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's the player's scoreboard objective.
|
||||
*
|
||||
* @return either existing objecting or new objective.
|
||||
*/
|
||||
public Objective getObjective() {
|
||||
Scoreboard scoreboard = getScoreboard();
|
||||
if (scoreboard.getObjective("Assemble") == null) {
|
||||
Objective objective = scoreboard.registerNewObjective("Assemble", "dummy");
|
||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
objective.setDisplayName(getAssemble().getAdapter().getTitle(Bukkit.getPlayer(getUuid())));
|
||||
return objective;
|
||||
} else {
|
||||
return scoreboard.getObjective("Assemble");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the board.
|
||||
*
|
||||
* @param player who's board to setup.
|
||||
*/
|
||||
private void setup(Player player) {
|
||||
Scoreboard scoreboard = getScoreboard();
|
||||
player.setScoreboard(scoreboard);
|
||||
getObjective();
|
||||
|
||||
// Send Update.
|
||||
AssembleBoardCreatedEvent createdEvent = new AssembleBoardCreatedEvent(this);
|
||||
Bukkit.getPluginManager().callEvent(createdEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the board entry at a specific position.
|
||||
*
|
||||
* @param pos to find entry.
|
||||
* @return entry if it isn't out of range.
|
||||
*/
|
||||
public AssembleBoardEntry getEntryAtPosition(int pos) {
|
||||
return pos >= this.entries.size() ? null : this.entries.get(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique identifier for position in scoreboard.
|
||||
*
|
||||
* @param position for identifier.
|
||||
* @return unique identifier.
|
||||
*/
|
||||
public String getUniqueIdentifier(int position) {
|
||||
String identifier = getRandomChatColor(position) + ChatColor.WHITE;
|
||||
|
||||
while (this.identifiers.contains(identifier)) {
|
||||
identifier = identifier + getRandomChatColor(position) + ChatColor.WHITE;
|
||||
}
|
||||
|
||||
// This is rare, but just in case, make the method recursive
|
||||
if (identifier.length() > 16) {
|
||||
return this.getUniqueIdentifier(position);
|
||||
}
|
||||
|
||||
// Add our identifier to the list so there are no duplicates
|
||||
this.identifiers.add(identifier);
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a ChatColor based off the position in the collection.
|
||||
*
|
||||
* @param position of entry.
|
||||
* @return ChatColor adjacent to position.
|
||||
*/
|
||||
private static String getRandomChatColor(int position) {
|
||||
return ChatColor.values()[position].toString();
|
||||
}
|
||||
|
||||
}
|
116
src/main/java/assemble/AssembleBoardEntry.java
Normal file
116
src/main/java/assemble/AssembleBoardEntry.java
Normal file
@ -0,0 +1,116 @@
|
||||
package assemble;
|
||||
|
||||
import lombok.Setter;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
public class AssembleBoardEntry {
|
||||
|
||||
private final AssembleBoard board;
|
||||
@Setter private String text, identifier;
|
||||
private Team team;
|
||||
private int position;
|
||||
|
||||
/**
|
||||
* Assemble Board Entry
|
||||
*
|
||||
* @param board that entry belongs to.
|
||||
* @param text of entry.
|
||||
* @param position of entry.
|
||||
*/
|
||||
public AssembleBoardEntry(AssembleBoard board, String text, int position) {
|
||||
this.board = board;
|
||||
this.text = text;
|
||||
this.position = position;
|
||||
this.identifier = this.board.getUniqueIdentifier(position);
|
||||
|
||||
this.setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup Board Entry.
|
||||
*/
|
||||
public void setup() {
|
||||
final Scoreboard scoreboard = this.board.getScoreboard();
|
||||
|
||||
if (scoreboard == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String teamName = this.identifier;
|
||||
|
||||
// This shouldn't happen, but just in case.
|
||||
if (teamName.length() > 16) {
|
||||
teamName = teamName.substring(0, 16);
|
||||
}
|
||||
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
|
||||
// Register the team if it does not exist.
|
||||
if (team == null) {
|
||||
team = scoreboard.registerNewTeam(teamName);
|
||||
}
|
||||
|
||||
// Add the entry to the team.
|
||||
if (team.getEntries() == null || team.getEntries().isEmpty() || !team.getEntries().contains(this.identifier)) {
|
||||
team.addEntry(this.identifier);
|
||||
}
|
||||
|
||||
// Add the entry if it does not exist.
|
||||
if (!this.board.getEntries().contains(this)) {
|
||||
this.board.getEntries().add(this);
|
||||
}
|
||||
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Board Entry Update.
|
||||
*
|
||||
* @param position of entry.
|
||||
*/
|
||||
public void send(int position) {
|
||||
if (this.text.length() > 16) {
|
||||
String prefix = this.text.substring(0, 16);
|
||||
String suffix;
|
||||
|
||||
if (prefix.charAt(15) == ChatColor.COLOR_CHAR) {
|
||||
prefix = prefix.substring(0, 15);
|
||||
suffix = this.text.substring(15, this.text.length());
|
||||
} else if (prefix.charAt(14) == ChatColor.COLOR_CHAR) {
|
||||
prefix = prefix.substring(0, 14);
|
||||
suffix = this.text.substring(14, this.text.length());
|
||||
} else {
|
||||
if (ChatColor.getLastColors(prefix).equalsIgnoreCase(ChatColor.getLastColors(this.identifier))) {
|
||||
suffix = this.text.substring(16, this.text.length());
|
||||
} else {
|
||||
suffix = ChatColor.getLastColors(prefix) + this.text.substring(16, this.text.length());
|
||||
}
|
||||
}
|
||||
|
||||
if (suffix.length() > 16) {
|
||||
suffix = suffix.substring(0, 16);
|
||||
}
|
||||
|
||||
this.team.setPrefix(prefix);
|
||||
this.team.setSuffix(suffix);
|
||||
} else {
|
||||
this.team.setPrefix(this.text);
|
||||
this.team.setSuffix("");
|
||||
}
|
||||
|
||||
Score score = this.board.getObjective().getScore(this.identifier);
|
||||
score.setScore(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Board Entry from Board.
|
||||
*/
|
||||
public void remove() {
|
||||
this.board.getIdentifiers().remove(this.identifier);
|
||||
this.board.getScoreboard().resetScores(this.identifier);
|
||||
}
|
||||
|
||||
}
|
14
src/main/java/assemble/AssembleException.java
Normal file
14
src/main/java/assemble/AssembleException.java
Normal file
@ -0,0 +1,14 @@
|
||||
package assemble;
|
||||
|
||||
public class AssembleException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Assemble Exception.
|
||||
*
|
||||
* @param message attributed to exception.
|
||||
*/
|
||||
public AssembleException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
51
src/main/java/assemble/AssembleListener.java
Normal file
51
src/main/java/assemble/AssembleListener.java
Normal file
@ -0,0 +1,51 @@
|
||||
package assemble;
|
||||
|
||||
import assemble.events.AssembleBoardCreateEvent;
|
||||
import assemble.events.AssembleBoardDestroyEvent;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
@Getter
|
||||
public class AssembleListener implements Listener {
|
||||
|
||||
private Assemble assemble;
|
||||
|
||||
/**
|
||||
* Assemble Listener.
|
||||
*
|
||||
* @param assemble instance.
|
||||
*/
|
||||
public AssembleListener(Assemble assemble) {
|
||||
this.assemble = assemble;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
AssembleBoardCreateEvent createEvent = new AssembleBoardCreateEvent(event.getPlayer());
|
||||
|
||||
Bukkit.getPluginManager().callEvent(createEvent);
|
||||
if (createEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getAssemble().getBoards().put(event.getPlayer().getUniqueId(), new AssembleBoard(event.getPlayer(), getAssemble()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
AssembleBoardDestroyEvent destroyEvent = new AssembleBoardDestroyEvent(event.getPlayer());
|
||||
|
||||
Bukkit.getPluginManager().callEvent(destroyEvent);
|
||||
if (destroyEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getAssemble().getBoards().remove(event.getPlayer().getUniqueId());
|
||||
event.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
}
|
||||
|
||||
}
|
26
src/main/java/assemble/AssembleStyle.java
Normal file
26
src/main/java/assemble/AssembleStyle.java
Normal file
@ -0,0 +1,26 @@
|
||||
package assemble;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum AssembleStyle {
|
||||
|
||||
KOHI(true, 15),
|
||||
VIPER(true, -1),
|
||||
MODERN(false, 1);
|
||||
|
||||
private boolean descending;
|
||||
private int startNumber;
|
||||
|
||||
/**
|
||||
* Assemble Style.
|
||||
*
|
||||
* @param descending whether the positions are going down or up.
|
||||
* @param startNumber from where to loop from.
|
||||
*/
|
||||
AssembleStyle(boolean descending, int startNumber) {
|
||||
this.descending = descending;
|
||||
this.startNumber = startNumber;
|
||||
}
|
||||
|
||||
}
|
127
src/main/java/assemble/AssembleThread.java
Normal file
127
src/main/java/assemble/AssembleThread.java
Normal file
@ -0,0 +1,127 @@
|
||||
package assemble;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AssembleThread extends Thread {
|
||||
|
||||
private Assemble assemble;
|
||||
|
||||
/**
|
||||
* Assemble Thread.
|
||||
*
|
||||
* @param assemble instance.
|
||||
*/
|
||||
AssembleThread(Assemble assemble) {
|
||||
this.assemble = assemble;
|
||||
this.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(true) {
|
||||
try {
|
||||
tick();
|
||||
sleep(assemble.getTicks() * 50);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick logic for thread.
|
||||
*/
|
||||
private void tick() {
|
||||
for (Player player : this.assemble.getPlugin().getServer().getOnlinePlayers()) {
|
||||
try {
|
||||
AssembleBoard board = this.assemble.getBoards().get(player.getUniqueId());
|
||||
|
||||
// This shouldn't happen, but just in case.
|
||||
if (board == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Scoreboard scoreboard = board.getScoreboard();
|
||||
Objective objective = board.getObjective();
|
||||
|
||||
if (scoreboard == null || objective == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Just make a variable so we don't have to
|
||||
// process the same thing twice.
|
||||
String title = ChatColor.translateAlternateColorCodes('&', this.assemble.getAdapter().getTitle(player));
|
||||
|
||||
// Update the title if needed.
|
||||
if (!objective.getDisplayName().equals(title)) {
|
||||
objective.setDisplayName(title);
|
||||
}
|
||||
|
||||
List<String> newLines = this.assemble.getAdapter().getLines(player);
|
||||
|
||||
// Allow adapter to return null/empty list to display nothing.
|
||||
if (newLines == null || newLines.isEmpty()) {
|
||||
board.getEntries().forEach(AssembleBoardEntry::remove);
|
||||
board.getEntries().clear();
|
||||
} else {
|
||||
if (newLines.size() > 15) {
|
||||
newLines = this.assemble.getAdapter().getLines(player).subList(0, 15);
|
||||
}
|
||||
|
||||
// Reverse the lines because scoreboard scores are in descending order.
|
||||
if (!this.assemble.getAssembleStyle().isDescending()) {
|
||||
Collections.reverse(newLines);
|
||||
}
|
||||
|
||||
// Remove excessive amount of board entries.
|
||||
if (board.getEntries().size() > newLines.size()) {
|
||||
for (int i = newLines.size(); i < board.getEntries().size(); i++) {
|
||||
AssembleBoardEntry entry = board.getEntryAtPosition(i);
|
||||
|
||||
if (entry != null) {
|
||||
entry.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update existing entries / add new entries.
|
||||
int cache = this.assemble.getAssembleStyle().getStartNumber();
|
||||
for (int i = 0; i < newLines.size(); i++) {
|
||||
AssembleBoardEntry entry = board.getEntryAtPosition(i);
|
||||
|
||||
// Translate any colors.
|
||||
String line = ChatColor.translateAlternateColorCodes('&', newLines.get(i));
|
||||
|
||||
// If the entry is null, just create a new one.
|
||||
// Creating a new AssembleBoardEntry instance will add
|
||||
// itself to the provided board's entries list.
|
||||
if (entry == null) {
|
||||
entry = new AssembleBoardEntry(board, line, i);
|
||||
}
|
||||
|
||||
// Update text, setup the team, and update the display values.
|
||||
entry.setText(line);
|
||||
entry.setup();
|
||||
entry.send(
|
||||
this.assemble.getAssembleStyle().isDescending() ? cache-- : cache++
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (player.getScoreboard() != scoreboard && !assemble.isHook()) {
|
||||
player.setScoreboard(scoreboard);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new AssembleException("There was an error updating " + player.getName() + "'s scoreboard.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
src/main/java/assemble/events/AssembleBoardCreateEvent.java
Normal file
31
src/main/java/assemble/events/AssembleBoardCreateEvent.java
Normal file
@ -0,0 +1,31 @@
|
||||
package assemble.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Getter @Setter
|
||||
public class AssembleBoardCreateEvent extends Event implements Cancellable {
|
||||
|
||||
@Getter public static HandlerList handlerList = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private boolean cancelled = false;
|
||||
|
||||
/**
|
||||
* Assemble Board Create Event.
|
||||
*
|
||||
* @param player that the board is being created for.
|
||||
*/
|
||||
public AssembleBoardCreateEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
30
src/main/java/assemble/events/AssembleBoardCreatedEvent.java
Normal file
30
src/main/java/assemble/events/AssembleBoardCreatedEvent.java
Normal file
@ -0,0 +1,30 @@
|
||||
package assemble.events;
|
||||
|
||||
import assemble.AssembleBoard;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Getter @Setter
|
||||
public class AssembleBoardCreatedEvent extends Event {
|
||||
|
||||
@Getter public static HandlerList handlerList = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
private final AssembleBoard board;
|
||||
|
||||
/**
|
||||
* Assemble Board Created Event.
|
||||
*
|
||||
* @param board of player.
|
||||
*/
|
||||
public AssembleBoardCreatedEvent(AssembleBoard board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
31
src/main/java/assemble/events/AssembleBoardDestroyEvent.java
Normal file
31
src/main/java/assemble/events/AssembleBoardDestroyEvent.java
Normal file
@ -0,0 +1,31 @@
|
||||
package assemble.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Getter @Setter
|
||||
public class AssembleBoardDestroyEvent extends Event implements Cancellable {
|
||||
|
||||
@Getter public static HandlerList handlerList = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private boolean cancelled = false;
|
||||
|
||||
/**
|
||||
* Assemble Board Destroy Event.
|
||||
*
|
||||
* @param player who's board got destroyed.
|
||||
*/
|
||||
public AssembleBoardDestroyEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package rip.tilly.bedwars;
|
||||
|
||||
import assemble.Assemble;
|
||||
import assemble.AssembleStyle;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
@ -8,6 +10,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import rip.tilly.bedwars.listeners.RandomListeners;
|
||||
import rip.tilly.bedwars.managers.ScoreboardManager;
|
||||
import rip.tilly.bedwars.mongo.MongoManager;
|
||||
import rip.tilly.bedwars.player.PlayerDataHandler;
|
||||
import rip.tilly.bedwars.player.PlayerDataManager;
|
||||
@ -41,6 +44,10 @@ public final class BedWars extends JavaPlugin {
|
||||
this.loadManagers();
|
||||
this.loadListeners();
|
||||
|
||||
Assemble assemble = new Assemble(this, new ScoreboardManager());
|
||||
assemble.setTicks(2);
|
||||
assemble.setAssembleStyle(AssembleStyle.VIPER);
|
||||
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
for (Entity entity : world.getEntities()) {
|
||||
if (entity.getType() != EntityType.PLAYER && entity.getType() != EntityType.ITEM_FRAME) {
|
||||
|
@ -4,44 +4,40 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.trixkz.bedwarspractice.Main;
|
||||
import xyz.trixkz.bedwarspractice.utils.Utils;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
public class LevelCommand implements CommandExecutor {
|
||||
|
||||
private Main main;
|
||||
|
||||
public LevelCommand(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (!player.hasPermission(Utils.ADMIN_PERMISSION_NODE)) {
|
||||
player.sendMessage(Utils.translate(Utils.NO_PERMISSION_MESSAGE));
|
||||
if (!player.hasPermission("bedwars.admin")) {
|
||||
player.sendMessage(CC.translate("&cNo permission"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(Utils.translate("&cUsage:"));
|
||||
player.sendMessage(Utils.translate(" &c/level"));
|
||||
player.sendMessage(Utils.translate(" &c/level set <player> <amount>"));
|
||||
player.sendMessage(Utils.translate(" &c/level add <player> <amount>"));
|
||||
player.sendMessage(Utils.translate(" &c/level remove <player> <amount>"));
|
||||
player.sendMessage(CC.translate("&cUsage:"));
|
||||
player.sendMessage(CC.translate(" &c/level"));
|
||||
player.sendMessage(CC.translate(" &c/level set <player> <amount>"));
|
||||
player.sendMessage(CC.translate(" &c/level add <player> <amount>"));
|
||||
player.sendMessage(CC.translate(" &c/level remove <player> <amount>"));
|
||||
} else {
|
||||
switch (args[0]) {
|
||||
case "set":
|
||||
new SetCommand(this.main).executeAs(sender, cmd, label, args);
|
||||
new SetCommand().executeAs(sender, cmd, label, args);
|
||||
|
||||
break;
|
||||
case "add":
|
||||
new AddCommand(this.main).executeAs(sender, cmd, label, args);
|
||||
new AddCommand().executeAs(sender, cmd, label, args);
|
||||
|
||||
break;
|
||||
case "remove":
|
||||
new RemoveCommand(this.main).executeAs(sender, cmd, label, args);
|
||||
new RemoveCommand().executeAs(sender, cmd, label, args);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -4,12 +4,9 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import xyz.trixkz.bedwarspractice.Main;
|
||||
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
|
||||
import xyz.trixkz.bedwarspractice.managers.user.User;
|
||||
import xyz.trixkz.bedwarspractice.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -3,21 +3,17 @@ package rip.tilly.bedwars.commands.level;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.trixkz.bedwarspractice.Main;
|
||||
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
|
||||
import xyz.trixkz.bedwarspractice.managers.user.User;
|
||||
import xyz.trixkz.bedwarspractice.utils.Utils;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SetCommand extends BaseCommand {
|
||||
|
||||
private Main main;
|
||||
|
||||
public SetCommand(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
@Override
|
||||
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
@ -25,23 +21,23 @@ public class SetCommand extends BaseCommand {
|
||||
|
||||
Player target = this.main.getServer().getPlayer(args[1]);
|
||||
|
||||
User user = User.getByUUID(target.getUniqueId());
|
||||
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
if (!target.isOnline()) {
|
||||
player.sendMessage(Utils.translate("&cError: Player is not currently online"));
|
||||
player.sendMessage(CC.translate("&cError: Player is not currently online"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.main.getUtils().isNumeric(args[2])) {
|
||||
player.sendMessage(Utils.translate("&cError: Please send a valid number"));
|
||||
if (!CC.isNumeric(args[2])) {
|
||||
player.sendMessage(CC.translate("&cError: Please send a valid number"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Integer amount = Integer.parseInt(args[2]);
|
||||
|
||||
user.getSettings().setLevel(amount);
|
||||
playerData.setLevel(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -3,21 +3,17 @@ package rip.tilly.bedwars.commands.xp;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.trixkz.bedwarspractice.Main;
|
||||
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
|
||||
import xyz.trixkz.bedwarspractice.managers.user.User;
|
||||
import xyz.trixkz.bedwarspractice.utils.Utils;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AddCommand extends BaseCommand {
|
||||
|
||||
private Main main;
|
||||
|
||||
public AddCommand(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
@Override
|
||||
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
@ -25,23 +21,23 @@ public class AddCommand extends BaseCommand {
|
||||
|
||||
Player target = this.main.getServer().getPlayer(args[1]);
|
||||
|
||||
User user = User.getByUUID(target.getUniqueId());
|
||||
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
if (!target.isOnline()) {
|
||||
player.sendMessage(Utils.translate("&cError: Player is not currently online"));
|
||||
player.sendMessage(CC.translate("&cError: Player is not currently online"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.main.getUtils().isNumeric(args[2])) {
|
||||
player.sendMessage(Utils.translate("&cError: Please send a valid number"));
|
||||
if (!CC.isNumeric(args[2])) {
|
||||
player.sendMessage(CC.translate("&cError: Please send a valid number"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
|
||||
user.getSettings().addXp(target, amount);
|
||||
playerData.setXp(playerData.getXp() + amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,21 +3,17 @@ package rip.tilly.bedwars.commands.xp;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.trixkz.bedwarspractice.Main;
|
||||
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
|
||||
import xyz.trixkz.bedwarspractice.managers.user.User;
|
||||
import xyz.trixkz.bedwarspractice.utils.Utils;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoveCommand extends BaseCommand {
|
||||
|
||||
private Main main;
|
||||
|
||||
public RemoveCommand(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
@Override
|
||||
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
@ -25,23 +21,23 @@ public class RemoveCommand extends BaseCommand {
|
||||
|
||||
Player target = this.main.getServer().getPlayer(args[1]);
|
||||
|
||||
User user = User.getByUUID(target.getUniqueId());
|
||||
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
if (!target.isOnline()) {
|
||||
player.sendMessage(Utils.translate("&cError: Player is not currently online"));
|
||||
player.sendMessage(CC.translate("&cError: Player is not currently online"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.main.getUtils().isNumeric(args[2])) {
|
||||
player.sendMessage(Utils.translate("&cError: Please send a valid number"));
|
||||
if (!CC.isNumeric(args[2])) {
|
||||
player.sendMessage(CC.translate("&cError: Please send a valid number"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
|
||||
user.getSettings().removeXp(amount);
|
||||
playerData.setXp(playerData.getXp() - amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,21 +3,17 @@ package rip.tilly.bedwars.commands.xp;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.trixkz.bedwarspractice.Main;
|
||||
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
|
||||
import xyz.trixkz.bedwarspractice.managers.user.User;
|
||||
import xyz.trixkz.bedwarspractice.utils.Utils;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SetCommand extends BaseCommand {
|
||||
|
||||
private Main main;
|
||||
|
||||
public SetCommand(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
@Override
|
||||
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
@ -25,23 +21,23 @@ public class SetCommand extends BaseCommand {
|
||||
|
||||
Player target = this.main.getServer().getPlayer(args[1]);
|
||||
|
||||
User user = User.getByUUID(target.getUniqueId());
|
||||
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
if (!target.isOnline()) {
|
||||
player.sendMessage(Utils.translate("&cError: Player is not currently online"));
|
||||
player.sendMessage(CC.translate("&cError: Player is not currently online"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.main.getUtils().isNumeric(args[2])) {
|
||||
player.sendMessage(Utils.translate("&cError: Please send a valid number"));
|
||||
if (!CC.isNumeric(args[2])) {
|
||||
player.sendMessage(CC.translate("&cError: Please send a valid number"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Double amount = Double.parseDouble(args[2]);
|
||||
|
||||
user.getSettings().setXp(amount);
|
||||
playerData.setXp(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,44 +4,40 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.trixkz.bedwarspractice.Main;
|
||||
import xyz.trixkz.bedwarspractice.utils.Utils;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
public class XpCommand implements CommandExecutor {
|
||||
|
||||
private Main main;
|
||||
|
||||
public XpCommand(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (!player.hasPermission(Utils.ADMIN_PERMISSION_NODE)) {
|
||||
player.sendMessage(Utils.translate(Utils.NO_PERMISSION_MESSAGE));
|
||||
if (!player.hasPermission("bedwars.admin")) {
|
||||
player.sendMessage(CC.translate("&cNo permission"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(Utils.translate("&cUsage:"));
|
||||
player.sendMessage(Utils.translate(" &c/xp"));
|
||||
player.sendMessage(Utils.translate(" &c/xp set <player> <amount>"));
|
||||
player.sendMessage(Utils.translate(" &c/xp add <player> <amount>"));
|
||||
player.sendMessage(Utils.translate(" &c/xp remove <player> <amount>"));
|
||||
player.sendMessage(CC.translate("&cUsage:"));
|
||||
player.sendMessage(CC.translate(" &c/xp"));
|
||||
player.sendMessage(CC.translate(" &c/xp set <player> <amount>"));
|
||||
player.sendMessage(CC.translate(" &c/xp add <player> <amount>"));
|
||||
player.sendMessage(CC.translate(" &c/xp remove <player> <amount>"));
|
||||
} else {
|
||||
switch (args[0]) {
|
||||
case "set":
|
||||
new SetCommand(this.main).executeAs(sender, cmd, label, args);
|
||||
new SetCommand().executeAs(sender, cmd, label, args);
|
||||
|
||||
break;
|
||||
case "add":
|
||||
new AddCommand(this.main).executeAs(sender, cmd, label, args);
|
||||
new AddCommand().executeAs(sender, cmd, label, args);
|
||||
|
||||
break;
|
||||
case "remove":
|
||||
new RemoveCommand(this.main).executeAs(sender, cmd, label, args);
|
||||
new RemoveCommand().executeAs(sender, cmd, label, args);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package rip.tilly.bedwars.managers;
|
||||
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.level.LevelCommand;
|
||||
import rip.tilly.bedwars.commands.setspawn.SetSpawnCommand;
|
||||
import rip.tilly.bedwars.commands.xp.XpCommand;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
@ -13,5 +15,7 @@ public class CommandManager {
|
||||
|
||||
private void registerCommands() {
|
||||
this.main.getCommand("setspawn").setExecutor(new SetSpawnCommand());
|
||||
this.main.getCommand("level").setExecutor(new LevelCommand());
|
||||
this.main.getCommand("xp").setExecutor(new XpCommand());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
package rip.tilly.bedwars.managers;
|
||||
|
||||
import assemble.AssembleAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScoreboardManager implements AssembleAdapter {
|
||||
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
@Override
|
||||
public String getTitle(Player player) {
|
||||
return CC.translate("&d&lBedWars");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLines(Player player) {
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
lines.add(CC.translate(CC.scoreboardBar));
|
||||
lines.add(CC.translate("&fOnline: &d" + this.main.getServer().getOnlinePlayers().size()));
|
||||
lines.add(CC.translate("&fPlaying: &d"));
|
||||
lines.add(CC.translate(""));
|
||||
|
||||
if (true) {
|
||||
lines.add(CC.translate("&fLevel: &d" + playerData.getLevel()));
|
||||
|
||||
String finishedProgress = "";
|
||||
|
||||
int notFinishedProgress = 10;
|
||||
|
||||
for (int i = 0; i < playerData.getXp() * 100; i++) {
|
||||
if (i % 10 == 0) {
|
||||
finishedProgress += "⬛";
|
||||
|
||||
notFinishedProgress--;
|
||||
}
|
||||
}
|
||||
|
||||
String leftOverProgress = "";
|
||||
|
||||
for (int i = 1; i <= notFinishedProgress; i++) {
|
||||
leftOverProgress += "⬛";
|
||||
}
|
||||
|
||||
lines.add(CC.translate("&8" + finishedProgress + "&7" + leftOverProgress + " &7(" + ((int) (playerData.getXp() * 100)) + "%&7)"));
|
||||
lines.add(CC.translate(""));
|
||||
}
|
||||
|
||||
lines.add(CC.translate("&dtilly.rip"));
|
||||
lines.add(CC.translate(CC.scoreboardBar));
|
||||
|
||||
return lines;
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ public class PlayerData {
|
||||
|
||||
private int kills;
|
||||
private int deaths;
|
||||
private int xp;
|
||||
private double xp;
|
||||
private int level;
|
||||
private int wins;
|
||||
private int losses;
|
||||
|
@ -40,7 +40,7 @@ public class PlayerDataManager {
|
||||
if (document != null) {
|
||||
playerData.setKills(document.getInteger("kills"));
|
||||
playerData.setDeaths(document.getInteger("deaths"));
|
||||
playerData.setXp(document.getInteger("xp"));
|
||||
playerData.setXp(document.getDouble("xp"));
|
||||
playerData.setLevel(document.getInteger("level"));
|
||||
playerData.setWins(document.getInteger("wins"));
|
||||
playerData.setLosses(document.getInteger("losses"));
|
||||
|
@ -1,9 +1,11 @@
|
||||
name: BedWars
|
||||
version: ${project.version}
|
||||
version: 1.0
|
||||
main: rip.tilly.bedwars.BedWars
|
||||
authors:
|
||||
- Lucanius
|
||||
- Trixkz
|
||||
|
||||
commands:
|
||||
setspawn:
|
||||
setspawn:
|
||||
level:
|
||||
xp:
|
Loading…
Reference in New Issue
Block a user