-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
PlayerHelper_v1_10_R1.java
121 lines (106 loc) · 4.2 KB
/
PlayerHelper_v1_10_R1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package net.aufdemrand.denizen.nms.helpers;
import com.mojang.authlib.GameProfile;
import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer;
import net.aufdemrand.denizen.nms.impl.ImprovedOfflinePlayer_v1_10_R1;
import net.aufdemrand.denizen.nms.interfaces.PlayerHelper;
import net.minecraft.server.v1_10_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class PlayerHelper_v1_10_R1 implements PlayerHelper {
@Override
public float getAbsorption(Player player) {
return ((CraftPlayer) player).getHandle().getDataWatcher().get(DataWatcherRegistry.c.a(11));
}
@Override
public void setAbsorption(Player player, float value) {
((CraftPlayer) player).getHandle().getDataWatcher().set(DataWatcherRegistry.c.a(11), value);
}
@Override
public boolean hasChunkLoaded(Player player, Chunk chunk) {
return ((CraftWorld) chunk.getWorld()).getHandle().getPlayerChunkMap()
.a(((CraftPlayer) player).getHandle(), chunk.getX(), chunk.getZ());
}
@Override
public int getPing(Player player) {
return ((CraftPlayer) player).getHandle().ping;
}
@Override
public void setTemporaryOp(Player player, boolean op) {
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
GameProfile profile = ((CraftPlayer) player).getProfile();
OpList opList = server.getPlayerList().getOPs();
if (op) {
int permLevel = server.q();
opList.add(new OpListEntry(profile, permLevel, opList.b(profile)));
}
else {
opList.remove(profile);
}
player.recalculatePermissions();
}
@Override
public void showEndCredits(Player player) {
((CraftPlayer) player).getHandle().viewingCredits = true;
((CraftPlayer) player).getHandle().playerConnection
.sendPacket(new PacketPlayOutGameStateChange(4, 0.0F));
}
@Override
public ImprovedOfflinePlayer getOfflineData(UUID uuid) {
return new ImprovedOfflinePlayer_v1_10_R1(uuid);
}
@Override
public ImprovedOfflinePlayer getOfflineData(OfflinePlayer offlinePlayer) {
return new ImprovedOfflinePlayer_v1_10_R1(offlinePlayer.getUniqueId());
}
/*
Boss Bars
*/
private static final Map<UUID, List<BossBar>> bossBars = new HashMap<UUID, List<BossBar>>();
@Override
public void showSimpleBossBar(Player player, String title, double progress) {
UUID uuid = player.getUniqueId();
if (!bossBars.containsKey(uuid)) {
bossBars.put(uuid, new ArrayList<BossBar>());
}
List<BossBar> playerBars = bossBars.get(uuid);
if (!playerBars.isEmpty()) {
Iterator<BossBar> iterator = playerBars.iterator();
while (iterator.hasNext()) {
BossBar bossBar = iterator.next();
bossBar.removePlayer(player);
iterator.remove();
}
}
BossBar bossBar = Bukkit.createBossBar(title, BarColor.PURPLE, BarStyle.SOLID);
bossBar.setProgress(progress);
bossBar.addPlayer(player);
bossBar.setVisible(true);
playerBars.add(bossBar);
}
@Override
public void removeSimpleBossBar(Player player) {
UUID uuid = player.getUniqueId();
if (bossBars.containsKey(uuid) && !bossBars.get(uuid).isEmpty()) {
Iterator<BossBar> iterator = bossBars.get(uuid).iterator();
while (iterator.hasNext()) {
BossBar bossBar = iterator.next();
bossBar.removePlayer(player);
iterator.remove();
}
}
}
}