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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/// <reference types="../../../CTAutocomplete" />
/// <reference lib="es2015" />
import { SoopyGui, SoopyRenderEvent } from "../../../guimanager";
import SoopyBoxElement from "../../../guimanager/GuiElement/SoopyBoxElement";
import SoopyGuiElement from "../../../guimanager/GuiElement/SoopyGuiElement";
import renderLibs from "../../../guimanager/renderLibs";
import Feature from "../../featureClass/class";
import ToggleSetting from "../settings/settingThings/toggle";
class AgentThings extends Feature {
constructor() {
super()
}
onEnable(){
this.initVariables()
this.nearPlayerData = []
while(this.nearPlayerData.length < 100){this.nearPlayerData.push({})}
this.recordNearestPlayers = new ToggleSetting("Record nearby players", "You can then view this data with /nearplayers", true, "record_near_players", this)
this.registerStep(false, 1, this.step)
this.nearPlayersGui = new SoopyGui().setOpenCommand("nearplayers")
this.nearPlayersGuiBox = new SoopyBoxElement().setLocation(0.25, 0.25, 0.5, 0.5)
this.nearPlayersGui.element.addChild(this.nearPlayersGuiBox)
this.nearPlayersRenderElement = new SoopyGuiElement()
this.nearPlayersGuiBox.addChild(this.nearPlayersRenderElement)
let selected = undefined
let selectedDist = undefined
let lastXY = 0
this.nearPlayersRenderElement.addEvent(new SoopyRenderEvent().setHandler((mouseX, mouseY)=>{
let moved = lastXY !== mouseX+mouseY
lastXY = mouseX+mouseY
let x = this.nearPlayersRenderElement.location.getXExact()
let y = this.nearPlayersRenderElement.location.getYExact()
let width = this.nearPlayersRenderElement.location.getWidthExact()
let height = this.nearPlayersRenderElement.location.getHeightExact()
x+=width*0.125
y+=height*0.125
width*=0.75
height*=0.75
Renderer.drawLine(Renderer.color(0, 0, 0), x, y+height, x+width, y+height, 2)//bottom axis line
Renderer.drawLine(Renderer.color(0, 0, 0), x, y, x, y+height, 2)//left axis line
renderLibs.drawStringCentered("&0100s ago", x, y+height+6, Renderer.screen.getWidth()/1000)
renderLibs.drawStringCentered("&050s ago", x+width/2, y+height+6, Renderer.screen.getWidth()/1000)
renderLibs.drawStringCentered("&0Now", x+width, y+height+6, Renderer.screen.getWidth()/1000) //bottom axis markers
renderLibs.drawStringCenteredVertically("&025m away", x+3-Renderer.getStringWidth("&025m away")*Renderer.screen.getWidth()/1000, y, Renderer.screen.getWidth()/1000)
renderLibs.drawStringCenteredVertically("&020m away", x+3-Renderer.getStringWidth("&020m away")*Renderer.screen.getWidth()/1000, y+height/5*1, Renderer.screen.getWidth()/1000)
renderLibs.drawStringCenteredVertically("&010m away", x+3-Renderer.getStringWidth("&010m away")*Renderer.screen.getWidth()/1000, y+height/5*3, Renderer.screen.getWidth()/1000)
renderLibs.drawStringCenteredVertically("&00m away", x+3-Renderer.getStringWidth("&00m away")*Renderer.screen.getWidth()/1000, y+height-6, Renderer.screen.getWidth()/1000)
if(moved){
selected = undefined
selectedDist = undefined
}
let lastUuids = []
this.nearPlayerData.forEach((data, i)=>{
let newLastUuids = []
Object.keys(data).forEach(uuid=>{
newLastUuids.push(uuid)
lastUuids = lastUuids.filter(a=>a!==uuid)
let dist = data[uuid].distance
let oldDist = this.nearPlayerData[i-1]?.[uuid]?.distance || 25
let thisX = x+(i)/100*width
let thisY = y+height-(dist/25)*height
if(moved && (thisX-mouseX)**2 + (thisY-mouseY)**2 < 3){
selected = uuid
selectedDist = dist
}
if(i !== 0){
Renderer.drawLine(Renderer.color(0, 0, 0), x+(i-1)/100*width, y+height-(oldDist/25)*height, thisX, thisY, 1)
}
Renderer.drawRect(Renderer.color(0, 0, 0), thisX-1, thisY-1, 3, 3)
})
lastUuids.forEach(uuid=>{
let dist = 25
let oldDist = this.nearPlayerData[i-1]?.[uuid]?.distance || 25
let thisX = x+(i)/100*width
let thisY = y+height-(dist/25)*height
if(i !== 0){
Renderer.drawLine(Renderer.color(0, 0, 0), x+(i-1)/100*width, y+height-(oldDist/25)*height, thisX, thisY, 1)
}
})
lastUuids = newLastUuids
})
if(selected){
width = this.nearPlayersRenderElement.location.getWidthExact()
height = this.nearPlayersRenderElement.location.getHeightExact()
width*=0.75
height*=0.75
renderLibs.scizzorFast(0,0,Renderer.screen.getWidth(), Renderer.screen.getHeight())
let selectedIgn = undefined
let lastRenderedSelected = false
this.nearPlayerData.forEach((data, i)=>{
if(data[selected]){
lastRenderedSelected = true
selectedIgn = data[selected].name
let dist = data[selected].distance
let oldDist = this.nearPlayerData[i-1]?.[selected]?.distance || 25
let thisX = x+(i)/100*width
let thisY = y+height-(dist/25)*height
if(i !== 0){
Renderer.drawLine(Renderer.color(255, 0, 0), x+(i-1)/100*width, y+height-(oldDist/25)*height, thisX, thisY, 3)
}
}else{
if(lastRenderedSelected){
lastRenderedSelected = false
let dist = 25
let oldDist = this.nearPlayerData[i-1]?.[selected]?.distance || 25
let thisX = x+(i)/100*width
let thisY = y+height-(dist/25)*height
if(i !== 0){
Renderer.drawLine(Renderer.color(255, 0, 0), x+(i-1)/100*width, y+height-(oldDist/25)*height, thisX, thisY, 3)
}
}
}
})
let width = Math.max(Renderer.getStringWidth(selectedIgn)*2, Renderer.getStringWidth("Distance: " + selectedDist.toFixed(1)))+8
let height = 32
renderLibs.drawBox([255, 255, 255], mouseX+10, mouseY-height/2, width,height, 3)
renderLibs.drawString("&0" + selectedIgn, mouseX+14, mouseY-height/2+3, 2)
renderLibs.drawString("&0Distance: &7" + selectedDist.toFixed(1) , mouseX+14, mouseY-height/2+21, 1)
}
}))
}
step(){
if(!this.recordNearestPlayers.getValue()) return
let thisSecondPlayerData = {}
World.getAllPlayers().forEach(p=>{
let distSq = (p.getX()-Player.getX())**2+(p.getY()-Player.getY())**2+(p.getZ()-Player.getZ())**2
if(distSq < 25*25 && distSq !== 0){
thisSecondPlayerData[p.getUUID().toString()] = {name: p.getName(), distance: Math.sqrt(distSq)}
}
})
this.nearPlayerData.push(thisSecondPlayerData)
if(this.nearPlayerData.length > 100) this.nearPlayerData.shift()
}
initVariables(){
this.recordNearestPlayers = undefined
this.nearPlayerData = undefined
this.nearPlayersGui = undefined
this.nearPlayersGuiBox = undefined
this.nearPlayersRenderElement = undefined
}
onDisable(){
this.nearPlayersGui.delete()
this.initVariables()
}
}
module.exports = {
class: new AgentThings()
}
|