Skip to content

Commit 28e8b60

Browse files
committed
bop
1 parent c05aca7 commit 28e8b60

7 files changed

Lines changed: 132 additions & 50 deletions

File tree

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<enabled>true</enabled>
3434
</snapshots>
3535
</repository>
36+
<repository>
37+
<id>spigotmc</id>
38+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
39+
</repository>
3640
</repositories>
3741

3842
<dependencies>
@@ -42,5 +46,10 @@
4246
<version>4.1.0-SNAPSHOT</version>
4347
<scope>provided</scope>
4448
</dependency>
49+
<dependency>
50+
<groupId>org.bukkit</groupId>
51+
<artifactId>bukkit</artifactId>
52+
<version>1.8.8-R0.1-SNAPSHOT</version>
53+
</dependency>
4554
</dependencies>
4655
</project>

src/main/java/me/dags/daflightmanager/ChannelHandler.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package me.dags.daflightmanager.bukkit;
2+
3+
import org.bukkit.entity.Player;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
/**
9+
* @author dags_ <dags@dags.me>
10+
*/
11+
class Config
12+
{
13+
Map<String, Float> flySpeeds = new HashMap<>();
14+
Map<String, Float> sprintSpeeds = new HashMap<>();
15+
16+
Float getMaxFlySpeed(Player player)
17+
{
18+
return max(flySpeeds, player, "fly");
19+
}
20+
21+
Float getMaxSprintSpeed(Player player)
22+
{
23+
return max(sprintSpeeds, player, "sprint");
24+
}
25+
26+
private Float max(Map<String, Float> speeds, Player player, String type)
27+
{
28+
return speeds.entrySet().stream()
29+
.filter(e -> player.hasPermission("daflight." + type + "." + e.getKey()))
30+
.map(Map.Entry::getValue)
31+
.max((i1, i2) -> i1 > i2 ? 1 : -1).orElse(0F);
32+
}
33+
34+
static Config defaultConfig()
35+
{
36+
Config config = new Config();
37+
config.flySpeeds.put("guest", 1F);
38+
config.flySpeeds.put("member", 5F);
39+
config.flySpeeds.put("moderator", 15F);
40+
config.flySpeeds.put("operator", 100F);
41+
config.sprintSpeeds.putAll(config.flySpeeds);
42+
return config;
43+
}
44+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package me.dags.daflightmanager.bukkit;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.configuration.Configuration;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
import org.bukkit.plugin.messaging.PluginMessageListener;
8+
9+
import java.nio.ByteBuffer;
10+
11+
public class DFMBukkit extends JavaPlugin implements PluginMessageListener
12+
{
13+
private Config config = Config.defaultConfig();
14+
15+
@Override
16+
public void onEnable()
17+
{
18+
Bukkit.getMessenger().registerIncomingPluginChannel(this, "DAFLIGHT-CONNECT", this);
19+
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "DAFLIGHT-FLY");
20+
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "DAFLIGHT-SPRINT");
21+
config = loadConfig();
22+
}
23+
24+
@Override
25+
public void onPluginMessageReceived(String s, Player player, byte[] bytes)
26+
{
27+
getLogger().info(String.format("DaFlight connect message received from user %s", player.getName()));
28+
29+
Float fly = config.getMaxFlySpeed(player);
30+
Float sprint = config.getMaxSprintSpeed(player);
31+
32+
byte[] flyData = ByteBuffer.allocate(4).putFloat(fly).array();
33+
byte[] sprintData = ByteBuffer.allocate(4).putFloat(sprint).array();
34+
35+
player.sendPluginMessage(this, "DAFLIGHT-FLY", flyData);
36+
player.sendPluginMessage(this, "DAFLIGHT-SPRINT", sprintData);
37+
}
38+
39+
private Config loadConfig()
40+
{
41+
Configuration configuration = getConfig();
42+
if (configuration.contains("flySpeeds") && configuration.contains("sprintSpeeds"))
43+
{
44+
Config config = new Config();
45+
configuration.getConfigurationSection("flySpeeds").getValues(false).entrySet().forEach(e -> {
46+
config.flySpeeds.put(e.getKey(), ((Double) e.getValue()).floatValue());
47+
});
48+
configuration.getConfigurationSection("sprintSpeeds").getValues(false).entrySet().forEach(e -> {
49+
config.flySpeeds.put(e.getKey(), ((Double) e.getValue()).floatValue());
50+
});
51+
return config;
52+
}
53+
configuration.set("flySpeeds", config.flySpeeds);
54+
configuration.set("sprintSpeeds", config.sprintSpeeds);
55+
saveConfig();
56+
return config;
57+
}
58+
}

src/main/java/me/dags/daflightmanager/Config.java renamed to src/main/java/me/dags/daflightmanager/sponge/Config.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.dags.daflightmanager;
1+
package me.dags.daflightmanager.sponge;
22

33
import ninja.leaping.configurate.objectmapping.Setting;
44
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@@ -20,18 +20,18 @@ public class Config
2020

2121
Float getMaxFlySpeed(Player player)
2222
{
23-
return max(flySpeeds, player);
23+
return max(flySpeeds, player, "fly");
2424
}
2525

2626
Float getMaxSprintSpeed(Player player)
2727
{
28-
return max(sprintSpeeds, player);
28+
return max(sprintSpeeds, player, "sprint");
2929
}
3030

31-
private Float max(Map<String, Float> speeds, Player player)
31+
private Float max(Map<String, Float> speeds, Player player, String type)
3232
{
3333
return speeds.entrySet().stream()
34-
.filter(e -> player.hasPermission("daflight.speed." + e.getKey()))
34+
.filter(e -> player.hasPermission("daflight." + type + "." + e.getKey()))
3535
.map(Map.Entry::getValue)
3636
.max((i1, i2) -> i1 > i2 ? 1 : -1).orElse(0F);
3737
}

src/main/java/me/dags/daflightmanager/DaFlightManager.java renamed to src/main/java/me/dags/daflightmanager/sponge/DFMSponge.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.dags.daflightmanager;
1+
package me.dags.daflightmanager.sponge;
22

33
import com.google.inject.Inject;
44
import ninja.leaping.configurate.ConfigurationNode;
@@ -24,26 +24,26 @@
2424
* @author dags <dags@dags.me>
2525
*/
2626
@Plugin(name = "DaFlightManager", id = "me.dags.daflightmanager", version = "2.0")
27-
public class DaFlightManager implements RawDataListener
27+
public class DFMSponge implements RawDataListener
2828
{
2929
private final Logger logger = LoggerFactory.getLogger("DaFlightManager");
3030

3131
@Inject
3232
@ConfigDir(sharedRoot = false)
3333
private Path configDir;
34+
3435
private Config config;
36+
private ChannelBinding.RawDataChannel flyChannel;
37+
private ChannelBinding.RawDataChannel sprintChannel;
3538

3639
@Listener
3740
public void init(GamePreInitializationEvent event)
3841
{
3942
config = loadConfig();
4043

4144
Sponge.getChannelRegistrar().createRawChannel(this, "DAFLIGHT-CONNECT").addListener(this);
42-
ChannelBinding.RawDataChannel flyChannel = Sponge.getChannelRegistrar().createRawChannel(this, "DAFLIGHT-FLY");
43-
ChannelBinding.RawDataChannel sprintChannel = Sponge.getChannelRegistrar().createRawChannel(this, "DAFLIGHT-SPRINT");
44-
45-
flyChannel.addListener(new ChannelHandler(flyChannel, p -> config.getMaxFlySpeed(p)));
46-
sprintChannel.addListener(new ChannelHandler(sprintChannel, p -> config.getMaxSprintSpeed(p)));
45+
flyChannel = Sponge.getChannelRegistrar().createRawChannel(this, "DAFLIGHT-FLY");
46+
sprintChannel = Sponge.getChannelRegistrar().createRawChannel(this, "DAFLIGHT-SPRINT");
4747
}
4848

4949
@Override
@@ -53,6 +53,12 @@ public void handlePayload(ChannelBuf data, RemoteConnection connection, Platform
5353
{
5454
Player player = ((PlayerConnection) connection).getPlayer();
5555
logger.info("DaFlight connect message received from user {}", player.getName());
56+
57+
Float fly = config.getMaxFlySpeed(player);
58+
Float sprint = config.getMaxSprintSpeed(player);
59+
60+
flyChannel.sendTo(player, b -> b.writeFloat(fly));
61+
sprintChannel.sendTo(player, b -> b.writeFloat(sprint));
5662
}
5763
}
5864

src/main/resources/plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: DaFlightManager
2+
version: 2.0
3+
main: me.dags.daflightmanager.bukkit.DFMBukkit

0 commit comments

Comments
 (0)