SteamWar/SpigotCore
Archiviert
13
0

Merge branch 'scoreboard' of SteamWar/SpigotCore into master

Dieser Commit ist enthalten in:
Lixfel 2020-01-07 18:12:16 +01:00 committet von Gitea
Commit 7bf299a97f
9 geänderte Dateien mit 467 neuen und 1 gelöschten Zeilen

3
.gitignore vendored
Datei anzeigen

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

Datei anzeigen

@ -0,0 +1,59 @@
package de.steamwar.scoreboard;
import net.minecraft.server.v1_10_R1.*;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.Map;
public class SWScoreboard_10 {
ScoreboardCallback callback;
private Scoreboard scoreboard;
private ScoreboardObjective obj;
private int switcher = 0; //switch zwischen 0 und 1
public SWScoreboard_10(ScoreboardCallback callback) {
this.callback = callback;
this.scoreboard = new Scoreboard();
this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.b);
obj.setDisplayName(this.callback.getTitle());
}
public void sendScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0);
sendPacket(player, removePacket);
sendPacket(player, createpacket);
for(Map.Entry<String, Integer> currentEntry : this.callback.getData().entrySet()) {
ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey());
score.setScore(currentEntry.getValue());
PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(score);
sendPacket(player, scorePacket);
}
switcher();
PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj);
sendPacket(player, displayPacket);
}
public void deleteScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
sendPacket(player, removePacket);
}
private void sendPacket(Player p, Packet<?> packet) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
}
private void switcher() {
switcher++;
if(switcher == 1)
switcher = 0;
}
}

Datei anzeigen

@ -0,0 +1,58 @@
package de.steamwar.scoreboard;
import net.minecraft.server.v1_12_R1.*;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.Map;
public class SWScoreboard_12 {
ScoreboardCallback callback;
private Scoreboard scoreboard;
private ScoreboardObjective obj;
private int switcher = 0; //switch zwischen 0 und 1
public SWScoreboard_12(ScoreboardCallback callback) {
this.callback = callback;
this.scoreboard = new Scoreboard();
this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.b);
obj.setDisplayName(this.callback.getTitle());
}
public void sendScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0);
sendPacket(player, removePacket);
sendPacket(player, createpacket);
for(Map.Entry<String, Integer> currentEntry : this.callback.getData().entrySet()) {
ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey());
score.setScore(currentEntry.getValue());
PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(score);
sendPacket(player, scorePacket);
}
switcher();
PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj);
sendPacket(player, displayPacket);
}
public void deleteScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
sendPacket(player, removePacket);
}
private void sendPacket(Player p, Packet<?> packet) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
}
private void switcher() {
switcher++;
if(switcher == 1)
switcher = 0;
}
}

Datei anzeigen

@ -0,0 +1,58 @@
package de.steamwar.scoreboard;
import net.minecraft.server.v1_14_R1.*;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.Map;
public class SWScoreboard_14 {
ScoreboardCallback callback;
private Scoreboard scoreboard;
private ScoreboardObjective obj;
private int switcher = 0; //switch zwischen 0 und 1
public SWScoreboard_14(ScoreboardCallback callback) {
this.callback = callback;
this.scoreboard = new Scoreboard();
this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.DUMMY, new ChatMessage("USELESS"), IScoreboardCriteria.EnumScoreboardHealthDisplay.HEARTS);
obj.setDisplayName(new ChatMessage(this.callback.getTitle()));
}
public void sendScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0);
sendPacket(player, removePacket);
sendPacket(player, createpacket);
for(Map.Entry<String, Integer> currentEntry : this.callback.getData().entrySet()) {
ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey());
score.setScore(currentEntry.getValue());
PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(ScoreboardServer.Action.CHANGE, this.obj.getName(), score.getPlayerName(), score.getScore());
sendPacket(player, scorePacket);
}
switcher();
PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj);
sendPacket(player, displayPacket);
}
public void deleteScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
sendPacket(player, removePacket);
}
private void sendPacket(Player p, Packet<?> packet) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
}
private void switcher() {
switcher++;
if(switcher == 1)
switcher = 0;
}
}

Datei anzeigen

@ -0,0 +1,58 @@
package de.steamwar.scoreboard;
import net.minecraft.server.v1_15_R1.*;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.Map;
public class SWScoreboard_15 {
ScoreboardCallback callback;
private Scoreboard scoreboard;
private ScoreboardObjective obj;
private int switcher = 0; //switch zwischen 0 und 1
public SWScoreboard_15(ScoreboardCallback callback) {
this.callback = callback;
this.scoreboard = new Scoreboard();
this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.DUMMY, new ChatMessage("USELESS"), IScoreboardCriteria.EnumScoreboardHealthDisplay.HEARTS);
obj.setDisplayName(new ChatMessage(this.callback.getTitle()));
}
public void sendScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(obj, 1);
PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(obj, 0);
sendPacket(player, removePacket);
sendPacket(player, createpacket);
for(Map.Entry<String, Integer> currentEntry : this.callback.getData().entrySet()) {
ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey());
score.setScore(currentEntry.getValue());
PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(ScoreboardServer.Action.CHANGE, this.obj.getName(), score.getPlayerName(), score.getScore());
sendPacket(player, scorePacket);
}
switcher();
PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj);
sendPacket(player, displayPacket);
}
public void deleteScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
sendPacket(player, removePacket);
}
private void sendPacket(Player p, Packet<?> packet) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
}
private void switcher() {
switcher++;
if(switcher == 1)
switcher = 0;
}
}

Datei anzeigen

@ -0,0 +1,58 @@
package de.steamwar.scoreboard;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.Map;
public class SWScoreboard_8 {
ScoreboardCallback callback;
private Scoreboard scoreboard;
private ScoreboardObjective obj;
private int switcher = 0; //switch zwischen 0 und 1
public SWScoreboard_8(ScoreboardCallback callback) {
this.callback = callback;
this.scoreboard = new Scoreboard();
this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.b);
obj.setDisplayName(this.callback.getTitle());
}
public void sendScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0);
sendPacket(player, removePacket);
sendPacket(player, createpacket);
for(Map.Entry<String, Integer> currentEntry : this.callback.getData().entrySet()) {
ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey());
score.setScore(currentEntry.getValue());
PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(score);
sendPacket(player, scorePacket);
}
switcher();
PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj);
sendPacket(player, displayPacket);
}
public void deleteScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
sendPacket(player, removePacket);
}
private void sendPacket(Player p, Packet<?> packet) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
}
private void switcher() {
switcher++;
if(switcher == 1)
switcher = 0;
}
}

Datei anzeigen

@ -0,0 +1,58 @@
package de.steamwar.scoreboard;
import net.minecraft.server.v1_9_R2.*;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.Map;
public class SWScoreboard_9 {
ScoreboardCallback callback;
private Scoreboard scoreboard;
private ScoreboardObjective obj;
private int switcher = 0; //switch zwischen 0 und 1
public SWScoreboard_9(ScoreboardCallback callback) {
this.callback = callback;
this.scoreboard = new Scoreboard();
this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.b);
obj.setDisplayName(this.callback.getTitle());
}
public void sendScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0);
sendPacket(player, removePacket);
sendPacket(player, createpacket);
for(Map.Entry<String, Integer> currentEntry : this.callback.getData().entrySet()) {
ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey());
score.setScore(currentEntry.getValue());
PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(score);
sendPacket(player, scorePacket);
}
switcher();
PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj);
sendPacket(player, displayPacket);
}
public void deleteScoreboard(Player player) {
PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1);
sendPacket(player, removePacket);
}
private void sendPacket(Player p, Packet<?> packet) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
}
private void switcher() {
switcher++;
if(switcher == 1)
switcher = 0;
}
}

Datei anzeigen

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

Datei anzeigen

@ -0,0 +1,104 @@
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 SWScoreboard() { }
private static HashMap<Player, Object> playerBoards = new HashMap<>(); //Object -> Scoreboard | Alle Versionen in der Map!
public static boolean createScoreboard(Player player, ScoreboardCallback callback) {
Object swScoreboardObject;
switch (Core.getVersion()) {
case 8:
swScoreboardObject = new SWScoreboard_8(callback);
break;
case 9:
swScoreboardObject = new SWScoreboard_9(callback);
break;
case 10:
swScoreboardObject = new SWScoreboard_10(callback);
break;
case 12:
swScoreboardObject = new SWScoreboard_12(callback);
break;
case 14:
swScoreboardObject = new SWScoreboard_14(callback);
break;
case 15:
swScoreboardObject = new SWScoreboard_15(callback);
break;
default:
return false; //Kein Scoreboard senden
}
playerBoards.put(player, swScoreboardObject);
return true;
}
public boolean removeScoreboard(Player player) {
if(playerBoards.containsKey(player)) {
switch (Core.getVersion()) {
case 8:
((SWScoreboard_8) playerBoards.get(player)).deleteScoreboard(player);
break;
case 9:
((SWScoreboard_9) playerBoards.get(player)).deleteScoreboard(player);
break;
case 10:
((SWScoreboard_10) playerBoards.get(player)).deleteScoreboard(player);
break;
case 12:
((SWScoreboard_12) playerBoards.get(player)).deleteScoreboard(player);
break;
case 14:
((SWScoreboard_14) playerBoards.get(player)).deleteScoreboard(player);
break;
case 15:
((SWScoreboard_15) playerBoards.get(player)).deleteScoreboard(player);
break;
default:
return false;
}
playerBoards.remove(player);
return true;
}
return false;
}
//Scoreboard Updater
static {
Bukkit.getScheduler().scheduleAsyncRepeatingTask(Core.getInstance(), () -> {
synchronized (playerBoards) {
for(Map.Entry<Player, Object> entry : playerBoards.entrySet()) {
switch (Core.getVersion()) {
case 8:
((SWScoreboard_8) entry.getValue()).sendScoreboard(entry.getKey());
break;
case 9:
((SWScoreboard_9) entry.getValue()).sendScoreboard(entry.getKey());
break;
case 10:
((SWScoreboard_10) entry.getValue()).sendScoreboard(entry.getKey());
break;
case 12:
((SWScoreboard_12) entry.getValue()).sendScoreboard(entry.getKey());
break;
case 14:
((SWScoreboard_14) entry.getValue()).sendScoreboard(entry.getKey());
break;
case 15:
((SWScoreboard_15) entry.getValue()).sendScoreboard(entry.getKey());
break;
}
}
}
}, 10, 5);
}
}