Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit b83d7cc

Browse files
committed
Merge branch 'release/1.1'
2 parents 7a0a10a + 12f4d02 commit b83d7cc

File tree

17 files changed

+509
-46
lines changed

17 files changed

+509
-46
lines changed

src/main/java/eu/quantumsociety/deltacraft/DeltaCraft.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import eu.quantumsociety.deltacraft.commands.home.HomesCommand;
66
import eu.quantumsociety.deltacraft.commands.home.SetHomeCommand;
77
import eu.quantumsociety.deltacraft.commands.kelp.KelpCommand;
8+
import eu.quantumsociety.deltacraft.commands.other.KahyCommand;
89
import eu.quantumsociety.deltacraft.commands.spectate.SpectateCommand;
9-
import eu.quantumsociety.deltacraft.listeners.ComposterListener;
10-
import eu.quantumsociety.deltacraft.listeners.KelpGrowListener;
11-
import eu.quantumsociety.deltacraft.listeners.SpawnerDestroyListener;
12-
import eu.quantumsociety.deltacraft.listeners.SpectateListener;
10+
import eu.quantumsociety.deltacraft.listeners.*;
1311
import eu.quantumsociety.deltacraft.managers.*;
1412
import eu.quantumsociety.deltacraft.utils.enums.Settings;
13+
import org.bukkit.entity.Player;
1514
import org.bukkit.plugin.PluginManager;
1615
import org.bukkit.plugin.java.JavaPlugin;
1716

@@ -52,17 +51,27 @@ public void onEnable() {
5251
debugMsg("Spectate loaded");
5352
this.getCommand("kelp").setExecutor(new KelpCommand(kelpConfigManager, this));
5453
debugMsg("Kelp farms loaded");
54+
this.getCommand("kahy").setExecutor(new KahyCommand(this));
55+
debugMsg("Kahy commands loaded");
5556

5657
// Events
5758
PluginManager plm = this.getServer().getPluginManager();
5859
plm.registerEvents(new SpectateListener(this), this);
5960
debugMsg("Spectate listener loaded");
6061
plm.registerEvents(new KelpGrowListener(this), this);
6162
debugMsg("Kelp listener loaded");
63+
plm.registerEvents(new CampfireListener(this), this);
64+
debugMsg("Campfire listener loaded");
6265
plm.registerEvents(new ComposterListener(this), this);
6366
debugMsg("Composter listener loaded");
6467
plm.registerEvents(new SpawnerDestroyListener(this), this);
6568
debugMsg("Spawner destroy listener loaded");
69+
plm.registerEvents(new ShulkerKillListener(), this);
70+
debugMsg("Shulker kill listener loaded");
71+
plm.registerEvents(new EndTeleportListener(this), this);
72+
debugMsg("End restriction listener loaded");
73+
plm.registerEvents(new KahyProtectionListener(this), this);
74+
debugMsg("Kahy protection listener loaded");
6675

6776
debugMsg("Loaded " + manager.getKelpCacheManager().getCount() + " kelp regions");
6877

@@ -116,5 +125,4 @@ public void debugMsg(String message) {
116125
getLogger().info("[Debug]: " + message);
117126
}
118127
}
119-
120128
}

src/main/java/eu/quantumsociety/deltacraft/classes/CachePlayer.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bukkit.GameMode;
55
import org.bukkit.Location;
66
import org.bukkit.entity.Player;
7+
import org.bukkit.util.Vector;
78

89
import java.util.UUID;
910

@@ -12,20 +13,23 @@ public class CachePlayer {
1213
private Location originalLocation;
1314
private GameMode prevGameMode;
1415
private Player player;
16+
private Vector originalVelocity;
17+
private float fallDistance;
1518

16-
public CachePlayer(Player p, Location originalLocation, GameMode prevGameMode) {
19+
public CachePlayer(Player p, Location originalLocation, GameMode prevGameMode, Vector originalVelocity, float fallDistance) {
1720
this.id = p.getUniqueId();
1821
this.originalLocation = originalLocation;
1922
this.prevGameMode = prevGameMode;
2023
this.player = p;
24+
this.originalVelocity = originalVelocity;
25+
this.fallDistance = fallDistance;
2126
}
2227

23-
public CachePlayer(UUID id, Location originalLocation, GameMode prevGameMode) {
24-
this(Bukkit.getPlayer(id), originalLocation, prevGameMode);
28+
public CachePlayer(UUID id, Location originalLocation, GameMode prevGameMode, Vector originalVelocity, float fallDistance) {
29+
this(Bukkit.getPlayer(id), originalLocation, prevGameMode, originalVelocity, fallDistance);
2530
}
2631

2732

28-
2933
public Location getOriginalLocation() {
3034
return this.originalLocation;
3135
}
@@ -38,5 +42,7 @@ public GameMode getPrevGameMode() {
3842
return this.prevGameMode;
3943
}
4044

41-
public Player getPlayer() { return player; }
45+
public Player getPlayer() {
46+
return player;
47+
}
4248
}

src/main/java/eu/quantumsociety/deltacraft/commands/afk/AfkCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AfkCommand : CommandExecutor {
1212
return true;
1313
}
1414

15-
val player: Player = sender
15+
// val player: Player = sender
1616

1717
return true
1818
}

src/main/java/eu/quantumsociety/deltacraft/commands/home/HomeCommand.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package eu.quantumsociety.deltacraft.commands.home
22

33
import eu.quantumsociety.deltacraft.DeltaCraft
44
import eu.quantumsociety.deltacraft.managers.HomesManager
5+
import eu.quantumsociety.deltacraft.utils.Extensions
56
import eu.quantumsociety.deltacraft.utils.TextHelper
67
import eu.quantumsociety.deltacraft.utils.enums.Permissions
78
import net.md_5.bungee.api.ChatColor
@@ -95,16 +96,18 @@ class HomeCommand(private val configManager: HomesManager) : CommandExecutor, Ta
9596
.append(TextHelper.infoText(" anyway.")).create()))
9697
.create()))
9798

98-
9999
player.spigot().sendMessage(*text.create())
100100
return true;
101101
}
102102

103+
if (Extensions.isIdiot(player)) {
104+
player.spigot().sendMessage(*TextHelper.attentionText("You cannot use home, because you're an idiot!"))
105+
return true;
106+
}
103107

104108
player.teleport(homeLocation)
105109
player.sendMessage("Welcome home!")
106110

107-
108111
// Effects on teleport
109112
val world = player.location.world!!
110113

@@ -141,5 +144,4 @@ class HomeCommand(private val configManager: HomesManager) : CommandExecutor, Ta
141144

142145
return list
143146
}
144-
145147
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package eu.quantumsociety.deltacraft.commands.other;
2+
3+
import eu.quantumsociety.deltacraft.DeltaCraft;
4+
import eu.quantumsociety.deltacraft.utils.Extensions;
5+
import eu.quantumsociety.deltacraft.utils.TextHelper;
6+
import eu.quantumsociety.deltacraft.utils.enums.Permissions;
7+
import net.md_5.bungee.api.ChatColor;
8+
import org.bukkit.GameMode;
9+
import org.bukkit.command.Command;
10+
import org.bukkit.command.CommandExecutor;
11+
import org.bukkit.command.CommandSender;
12+
import org.bukkit.entity.Player;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
public class KahyCommand implements CommandExecutor {
16+
private final DeltaCraft plugin;
17+
18+
public KahyCommand(DeltaCraft plugin) {
19+
this.plugin = plugin;
20+
}
21+
22+
/**
23+
* Executes the given command, returning its success.
24+
* <br>
25+
* If false is returned, then the "usage" plugin.yml entry for this command
26+
* (if defined) will be sent to the player.
27+
*
28+
* @param sender Source of the command
29+
* @param command Command which was executed
30+
* @param label Alias of the command which was used
31+
* @param args Passed command arguments
32+
* @return true if a valid command, otherwise false
33+
*/
34+
@Override
35+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
36+
if (!(sender instanceof Player)) {
37+
sender.sendMessage("Only players can use this commands");
38+
return false;
39+
}
40+
Player p = (Player) sender;
41+
if (!p.hasPermission(Permissions.KAHYUSE.getPath())) {
42+
p.spigot().sendMessage(TextHelper.insufficientPermissions(Permissions.KAHYUSE));
43+
return true;
44+
}
45+
46+
if (p.getGameMode() != GameMode.SURVIVAL) {
47+
p.spigot().sendMessage(TextHelper.attentionText("This command can be used only in survival mode"));
48+
return true;
49+
}
50+
51+
if (Extensions.isKahy(p)) {
52+
p.spigot().sendMessage(TextHelper.attentionText("Kahy, you cannot use protection against yourself"));
53+
return true;
54+
}
55+
56+
if (Extensions.hasProtection(p)) {
57+
p.removeMetadata(Extensions.kahyProtectionKey, plugin);
58+
p.spigot().sendMessage(TextHelper.infoText("Kahy protection disabled"));
59+
return true;
60+
}
61+
62+
p.setMetadata(Extensions.kahyProtectionKey, Extensions.getFakeMetadata(plugin));
63+
p.spigot().sendMessage(TextHelper.infoText("Kahy protection enabled", ChatColor.GREEN));
64+
return true;
65+
}
66+
}

src/main/java/eu/quantumsociety/deltacraft/commands/spectate/SpectateCommand.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import eu.quantumsociety.deltacraft.DeltaCraft
44
import eu.quantumsociety.deltacraft.managers.SpectateManager
55
import eu.quantumsociety.deltacraft.managers.cache.SpectateCacheManager
66
import eu.quantumsociety.deltacraft.managers.cache.FakePlayerManager
7+
import eu.quantumsociety.deltacraft.utils.Extensions
78
import eu.quantumsociety.deltacraft.utils.KeyHelper
89
import eu.quantumsociety.deltacraft.utils.TextHelper
910
import eu.quantumsociety.deltacraft.utils.enums.Permissions
@@ -14,6 +15,7 @@ import org.bukkit.command.Command
1415
import org.bukkit.command.CommandExecutor
1516
import org.bukkit.command.CommandSender
1617
import org.bukkit.entity.Player
18+
import org.bukkit.util.Vector
1719

1820
class SpectateCommand(private val configManager: SpectateManager, private val plugin: DeltaCraft, private val fakePlayerHelper: FakePlayerManager = FakePlayerManager(plugin)) : CommandExecutor {
1921
private val spectateCache: SpectateCacheManager
@@ -43,19 +45,25 @@ class SpectateCommand(private val configManager: SpectateManager, private val pl
4345
private fun switchBack(p: Player, keys: KeyHelper): Boolean {
4446
val l = configManager.getLocation(keys)
4547
val g = configManager.getGamemode(keys)
48+
val vel = configManager.getVelocity(keys)
49+
val fallDis = configManager.getFallDistance(keys)
4650
p.setPlayerListName(p.name)
4751

4852
fakePlayerHelper.despawnFakePlayerToAll(p)
4953

50-
return switchBack(p, l, g)
54+
return switchBack(p, l, g, vel, fallDis)
5155
}
5256

53-
private fun switchBack(p: Player, l: Location, gm: GameMode): Boolean {
57+
private fun switchBack(p: Player, l: Location, gm: GameMode, velocity: Vector, fallDistance: Float): Boolean {
58+
p.setMetadata(this.spectateCache.teleportBackKey, Extensions.getFakeMetadata(plugin))
59+
5460
val id = p.uniqueId
5561
spectateCache.removeItem(id)
5662
configManager.delete(id)
5763
p.teleport(l)
5864
p.gameMode = gm
65+
p.velocity = velocity
66+
p.fallDistance = fallDistance
5967
p.sendMessage(ChatColor.YELLOW.toString() + "You are no longer Spectating!")
6068
return true
6169
}
@@ -65,9 +73,12 @@ class SpectateCommand(private val configManager: SpectateManager, private val pl
6573

6674
val loc = p.location
6775
val gm = p.gameMode
68-
configManager.save(keys, loc, gm)
69-
spectateCache.addItem(p, loc, gm)
76+
val vel = p.velocity
77+
val dis = p.fallDistance
78+
configManager.save(keys, loc, gm, vel, dis)
79+
spectateCache.addItem(p, loc, gm, vel, dis)
7080
p.gameMode = GameMode.SPECTATOR
81+
7182
p.spigot().sendMessage(*TextHelper.infoText("You are now Spectating!"))
7283
p.setPlayerListName("${p.name} (Spectating) ")
7384
return true
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package eu.quantumsociety.deltacraft.listeners
2+
3+
import eu.quantumsociety.deltacraft.DeltaCraft
4+
import org.bukkit.Material
5+
import org.bukkit.block.Campfire
6+
import org.bukkit.block.Dispenser
7+
import org.bukkit.block.data.Directional
8+
import org.bukkit.event.EventHandler
9+
import org.bukkit.event.Listener
10+
import org.bukkit.event.block.BlockDispenseEvent
11+
import org.bukkit.inventory.ItemStack
12+
13+
class CampfireListener(private val plugin: DeltaCraft) : Listener {
14+
15+
@EventHandler(ignoreCancelled = true)
16+
fun onBlockDispenseEvent(event: BlockDispenseEvent) {
17+
val emitter = event.block
18+
if (emitter.type != Material.DISPENSER) {
19+
return
20+
}
21+
22+
val emitterDirectional = emitter.blockData as Directional
23+
val direction = emitterDirectional.facing.direction
24+
val destination = emitter.location.clone()
25+
.add(direction).block
26+
27+
if (destination.type != Material.CAMPFIRE &&
28+
destination.type != Material.SOUL_CAMPFIRE) {
29+
return
30+
}
31+
32+
val item = event.item.clone()
33+
val type = item.type
34+
if (type != Material.BEEF &&
35+
type != Material.CHICKEN &&
36+
type != Material.RABBIT &&
37+
type != Material.PORKCHOP &&
38+
type != Material.MUTTON &&
39+
type != Material.COD &&
40+
type != Material.SALMON &&
41+
type != Material.POTATO &&
42+
type != Material.KELP) {
43+
return
44+
}
45+
46+
if (destination.state !is Campfire) {
47+
return
48+
}
49+
50+
val campfire = destination.state as Campfire
51+
var position = -1
52+
when {
53+
campfire.getItem(0) == null -> {
54+
position = 0
55+
}
56+
campfire.getItem(1) == null -> {
57+
position = 1
58+
}
59+
campfire.getItem(2) == null -> {
60+
position = 2
61+
}
62+
campfire.getItem(3) == null -> {
63+
position = 3
64+
}
65+
}
66+
67+
if (position >= 0) {
68+
item.amount = 1
69+
70+
campfire.setCookTime(position, 0)
71+
campfire.setCookTimeTotal(position, 600)
72+
campfire.setItem(position, item)
73+
campfire.update()
74+
75+
event.isCancelled = true
76+
77+
plugin.server.scheduler.runTaskLater(plugin, Runnable {
78+
val origState = event.block.state
79+
if (origState is Dispenser) {
80+
val inv = origState.inventory;
81+
inv.removeItem(ItemStack(event.item.type, 1))
82+
}
83+
}, 2)
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)