SteamWar/SpigotCore
Archiviert
13
0

WIP: scoreboard #12

Geschlossen
Lixfel möchte 22 Commits von scoreboard nach master mergen
10 geänderte Dateien mit 297 neuen und 1 gelöschten Zeilen

3
.gitignore vendored
Datei anzeigen

@ -1,3 +1,4 @@
.idea
target
dependency-reduced-pom.xml
dependency-reduced-pom.xml
*.iml

Datei anzeigen

@ -33,5 +33,10 @@
<version>1.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>SpigotCore_8</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,65 @@
package de.steamwar.scoreboard;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import net.minecraft.server.v1_12_R1.IScoreboardCriteria;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
public class SWScoreboard_12 {
private SWScoreboard_12() {}
static void sendRemovePacket(Player player) {
SWScoreboard_8.sendRemovePacket(player);
}
static void sendCreatePacket(String title, Player player) {
PacketContainer createPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
createPacket.getStrings().write(0, "AAA");
createPacket.getIntegers().write(0, 0);
createPacket.getStrings().write(1, title);
StructureModifier modifier = createPacket.getEnumModifier(IScoreboardCriteria.EnumScoreboardHealthDisplay.class, 0);
modifier.write(0, SWEnumScoreboardHealtyDisplay.INTEGER);
sendPacket(player, createPacket);
}
static void sendUpdatePacket(String content, Integer line, Player player) {
SWScoreboard_8.sendUpdatePacket(content, line, player);
}
static void sendDisplayPacket(Player player) {
SWScoreboard_8.sendDisplayPacket(player);
}
private static void sendPacket(Player player, PacketContainer packetContainer) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer);
} catch (InvocationTargetException ex) {
Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex);
}
}
static enum SWEnumScoreboardHealtyDisplay {
INTEGER("integer"),
HEARTS("hearts");
private String string;
private SWEnumScoreboardHealtyDisplay(String string) {
this.string = string;
}
public String getString() {
return string;
}
}
}

Datei anzeigen

@ -33,5 +33,10 @@
<version>1.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>SpigotCore_8</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,33 @@
package de.steamwar.scoreboard;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
public class SWScoreboard_14 {
private SWScoreboard_14() {}
static PacketContainer getRemovePacket() {
return null; //Todo SWScoreboard_8.getRemovePacket();
}
static PacketContainer getCreatePacket(String title) {
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, title);
createpacket.getIntegers().write(0, 0);
return createpacket;
}
static PacketContainer getUpdatePacket(String content, Integer line) {
return null; //todo SWScoreboard_8.getUpdatePacket(content, line);
}
static PacketContainer getDisplayPacket(String title) {
return null; //TOdo SWScoreboard_8.getDisplayPacket(title);
}
}

Datei anzeigen

@ -0,0 +1,63 @@
package de.steamwar.scoreboard;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import net.minecraft.server.v1_8_R3.IScoreboardCriteria;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
public class SWScoreboard_8 {
private SWScoreboard_8() {}
static void sendRemovePacket(Player player) {
PacketContainer removePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
removePacket.getStrings().write(0, "AAA");
removePacket.getIntegers().write(0, 1);
//TODO kann vlt entfernt werden -> remove.getStrings().write(1, "integer");
sendPacket(player, removePacket);
}
static void sendCreatePacket(String title, Player player) {
PacketContainer createPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
createPacket.getStrings().write(0, "AAA");
createPacket.getIntegers().write(0, 0);
createPacket.getStrings().write(1, title);
createPacket.getEnumModifier(IScoreboardCriteria.EnumScoreboardHealthDisplay.class, 0).write(0, IScoreboardCriteria.EnumScoreboardHealthDisplay.INTEGER);
sendPacket(player, createPacket);
}
static void sendUpdatePacket(String content, Integer line, Player player) {
PacketContainer updatePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_SCORE);
updatePacket.getStrings().write(0, content);
updatePacket.getStrings().write(1, "AAA");
updatePacket.getIntegers().write(0, line);
updatePacket.getBytes().write(0, (byte) 0);
sendPacket(player, updatePacket);
}
static void sendDisplayPacket(Player player) {
PacketContainer displayPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE);
displayPacket.getIntegers().write(0, 1);
displayPacket.getStrings().write(0, "AAA");
sendPacket(player, displayPacket);
}
private static void sendPacket(Player player, PacketContainer packetContainer) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer);
} catch (InvocationTargetException ex) {
Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex);
}
}
}

Datei anzeigen

@ -1,5 +1,7 @@
package de.steamwar.core.events;
import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -7,6 +9,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashMap;
public class PlayerJoinedEvent implements Listener{
@ -44,6 +48,24 @@ public class PlayerJoinedEvent implements Listener{
}
event.setJoinMessage("§a§l» §r" + player.getDisplayName());
//TEST
SWScoreboard swScoreboard = new SWScoreboard(new ScoreboardCallback() {
@Override
public HashMap<String, Integer> getData() {
HashMap<String, Integer> data = new HashMap<>();
data.put("bla", 2);
data.put("lala", 3);
return data;
}
@Override
public String getTitle() {
return "ES GEHT!!!!";
}
});
SWScoreboard.getPlayerBoards().put(player, swScoreboard);
}
@EventHandler
@ -51,5 +73,7 @@ public class PlayerJoinedEvent implements Listener{
Player player = event.getPlayer();
event.setQuitMessage("§c§l« §r" + player.getDisplayName());
SWScoreboard.getPlayerBoards().remove(player);
}
}

Datei anzeigen

@ -0,0 +1,79 @@
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.Map;
public class SWScoreboard {
private static HashMap<Player, SWScoreboard> playerBoards = new HashMap<>();
ScoreboardCallback callback;
public SWScoreboard(ScoreboardCallback callback) {
this.callback = callback;
}
private void sendScoreboard(Player player) {
switch (Core.getVersion()) {
case 8:
SWScoreboard_8.sendRemovePacket(player);
SWScoreboard_8.sendCreatePacket(this.callback.getTitle(), player);
break;
case 14:
//Todo remove = SWScoreboard_14.getRemovePacket();
//Todo createpacket = SWScoreboard_14.getCreatePacket(this.callback.getTitle());
break;
default:
SWScoreboard_12.sendRemovePacket(player);
SWScoreboard_12.sendCreatePacket(this.callback.getTitle(), player);
}
for(Map.Entry<String, Integer> entry : this.callback.getData().entrySet()) {
switch (Core.getVersion()) {
case 8:
SWScoreboard_8.sendUpdatePacket(entry.getKey(), entry.getValue(), player);
break;
case 14:
//Todo update = SWScoreboard_14.getUpdatePacket(entry.getKey(), entry.getValue());
break;
default:
SWScoreboard_12.sendUpdatePacket(entry.getKey(), entry.getValue(), player);
}
}
}
private void display(Player player) {
switch (Core.getVersion()) {
case 8:
SWScoreboard_8.sendDisplayPacket(player);
break;
case 14:
//Todo display = SWScoreboard_14.getDisplayPacket(this.callback.getTitle());
break;
default:
SWScoreboard_12.sendDisplayPacket(player);
}
}
static {
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getInstance(), () -> {
synchronized (playerBoards) {
for(Map.Entry<Player, SWScoreboard> entry : playerBoards.entrySet()) {
entry.getValue().sendScoreboard(entry.getKey());
entry.getValue().display(entry.getKey());
}
}
}, 10, 5);
}
public static HashMap<Player, SWScoreboard> getPlayerBoards() {
return playerBoards;
}
}

Datei anzeigen

@ -0,0 +1,12 @@
package de.steamwar.scoreboard;
import java.util.HashMap;
public interface ScoreboardCallback {
public HashMap<String, Integer> getData();
public String getTitle();
}

Datei anzeigen

@ -42,4 +42,13 @@
<module>SpigotCore_14</module>
<module>SpigotCore_Main</module>
</modules>
<dependencies>
<dependency>
<groupId>steamwar</groupId>
<artifactId>ProtocolLib</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>