cleanup
Dieser Commit ist enthalten in:
Ursprung
fbbbc450fb
Commit
d4dcbfeafa
@ -2,6 +2,7 @@ package de.steamwar.core;
|
||||
|
||||
import de.steamwar.core.events.ChattingEvent;
|
||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||
import de.steamwar.scoreboard.SWScoreboard;
|
||||
import de.steamwar.sql.SQL;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -34,6 +35,8 @@ public class Core extends JavaPlugin{
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
||||
|
||||
SWScoreboard.startPlayerBoards();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.steamwar.core.events;
|
||||
|
||||
import de.steamwar.scoreboard.SWScoreboard;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -51,5 +52,7 @@ public class PlayerJoinedEvent implements Listener{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
event.setQuitMessage("§c§l« §r" + player.getDisplayName());
|
||||
|
||||
SWScoreboard.getPlayerBoards().remove(player);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package de.steamwar.scoreboard;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -13,17 +14,15 @@ import java.util.logging.Level;
|
||||
|
||||
public class SWScoreboard {
|
||||
|
||||
HashMap<String, Integer> data;
|
||||
private Player player;
|
||||
private String title;
|
||||
private static HashMap<Player, SWScoreboard> playerBoards = new HashMap<>();
|
||||
|
||||
public SWScoreboard(Player player, HashMap<String, Integer> data, String title) {
|
||||
this.data = data;
|
||||
this.player = player;
|
||||
this.title = title;
|
||||
ScoreboardCallback callback;
|
||||
|
||||
public SWScoreboard(Player player, ScoreboardCallback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void sendScoreboard() {
|
||||
public void sendScoreboard(Player player) {
|
||||
PacketContainer remove = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
|
||||
remove.getStrings().write(0, "AAA");
|
||||
remove.getBytes().write(0, (byte) 1);
|
||||
@ -31,7 +30,7 @@ public class SWScoreboard {
|
||||
PacketContainer createpacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
|
||||
createpacket.getStrings().write(0, "AAA");
|
||||
createpacket.getBytes().write(0, (byte) 0);
|
||||
createpacket.getStrings().write(1, this.title);
|
||||
createpacket.getStrings().write(1, this.callback.getTitle());
|
||||
createpacket.getIntegers().write(0, 0);
|
||||
|
||||
try {
|
||||
@ -41,7 +40,7 @@ public class SWScoreboard {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex);
|
||||
}
|
||||
|
||||
for(Map.Entry<String, Integer> entry : data.entrySet()) {
|
||||
for(Map.Entry<String, Integer> entry : this.callback.getData().entrySet()) {
|
||||
PacketContainer update = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_SCORE);
|
||||
update.getStrings().write(0, entry.getKey());
|
||||
update.getBytes().write(0, (byte) 0);
|
||||
@ -57,10 +56,10 @@ public class SWScoreboard {
|
||||
|
||||
}
|
||||
|
||||
public void display() {
|
||||
public void display(Player player) {
|
||||
PacketContainer display = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE);
|
||||
display.getBytes().write(0, (byte) 1);
|
||||
display.getStrings().write(0, this.title);
|
||||
display.getStrings().write(0, this.callback.getTitle());
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, display);
|
||||
@ -69,27 +68,30 @@ public class SWScoreboard {
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getData() {
|
||||
return data;
|
||||
public static void startPlayerBoards() {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (playerBoards) {
|
||||
for(Map.Entry<Player, SWScoreboard> entry : playerBoards.entrySet()) {
|
||||
entry.getValue().sendScoreboard(entry.getKey());
|
||||
entry.getValue().display(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 10, 5);
|
||||
}
|
||||
|
||||
public void setData(HashMap<String, Integer> data) {
|
||||
this.data = data;
|
||||
|
||||
public ScoreboardCallback getCallback() {
|
||||
return callback;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
public void setCallback(ScoreboardCallback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
public static HashMap<Player, SWScoreboard> getPlayerBoards() {
|
||||
return playerBoards;
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
package de.steamwar.scoreboard;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ScoreboardContainer {
|
||||
|
||||
private static HashMap<UUID, ScoreboardContainer> containers = new HashMap<>();
|
||||
|
||||
Player player;
|
||||
ScoreboardCallback callback;
|
||||
|
||||
public ScoreboardContainer(Player player, ScoreboardCallback callback) {
|
||||
this.player = player;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
//Update
|
||||
SWScoreboard update = new SWScoreboard(player, callback.getData(), callback.getTitle());
|
||||
update.sendScoreboard();
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
update.display();
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
|
||||
public void startScoreboard() {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(ScoreboardContainer container : ScoreboardContainer.getContainers().values()) {
|
||||
container.update();
|
||||
}
|
||||
}
|
||||
}, 10, 5);
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static HashMap<UUID, ScoreboardContainer> getContainers() {
|
||||
return containers;
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren