Skip to content

Commit

Permalink
Add conscript and prolong cmds. Enchants on starting tools. Milk buck…
Browse files Browse the repository at this point in the history
…et event.
  • Loading branch information
icicl authored Jun 1, 2022
1 parent 169aa67 commit a87c3b5
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 59 deletions.
81 changes: 73 additions & 8 deletions src/BingoCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,54 @@ public boolean onCommand(
if (plugin.game != null) {
if (plugin.game.get_player(player) != null) {
player.sendMessage(
"You are already a participant in the current bingo game."
"You are already a participant in the current bingo game."
);
return true;
}
plugin.game.join(player);
} else {
player.sendMessage(
"No instance of bingo. Ask an admin to create one with §a/bingo new§f."
"No instance of bingo. Ask an admin to create one with §a/bingo new§f."
);
}
return true;
}
if (args[0].equalsIgnoreCase("conscript")) {
if (args.length == 1) {
sender.sendMessage("/bingo conscript [player]. to add all online players, use the wildcard *");
return true;
}
if (plugin.game == null) {
sender.sendMessage(
"No instance of bingo. Ask an admin to create one with §a/bingo new§f."
);
return true;
}
for (int i = 1; i < args.length; i++) {
if (args[i].equals("*")) {
for (Player bp : Bukkit.getOnlinePlayers()) {
if (plugin.game.get_player(bp) != null) {
sender.sendMessage(
bp.getDisplayName() + " is already a participant in the current bingo game."
);
} else {
plugin.game.join(bp);
}
}
return true;
}
player = Bukkit.getPlayer(args[i]);
if (player == null) {
sender.sendMessage("Player " + args[i] + " was not found online.");
} else {
if (plugin.game.get_player(player) != null) {
sender.sendMessage(
args[i] + " is already a participant in the current bingo game."
);
} else {
plugin.game.join(player);
}
}
}
return true;
}
Expand Down Expand Up @@ -306,14 +345,28 @@ public boolean onCommand(
player.teleport(
new Location(
player.getWorld(),
(double) px,
(double) px + 0.5,
(double) top_block.getLocation().getBlockY() + 1,
(double) pz
(double) pz + 0.5//todo
)
);
player.sendMessage("Teleported you to the surface.");
return true;
}
if (args[0].equalsIgnoreCase("prolong")) {
if (args.length != 2) {
sender.sendMessage(
"Usage: /bingo prolong [timeInSeconds]"
);
return true;
}
if (plugin.game == null) {
sender.sendMessage("No instance of bingo. Ask an admin to create one with §a/bingo new§f.");
return true;
}
plugin.game.prolong(Integer.parseInt(args[1]));
return true;
}
if (args[0].equalsIgnoreCase("about")){
sender.sendMessage("Bingo v§c"+plugin.getDescription().getVersion()+"§f by §aicicl§f.");
return true;
Expand All @@ -328,10 +381,22 @@ public boolean onCommand(
" creates a new bingo game, and allows players to join it."
);
sender.sendMessage(
pref +
"/bingo join" +
suff +
" joins the current bingo game, if it exists and has not yet finished."
pref +
"/bingo join" +
suff +
" joins the current bingo game, if it exists and has not yet finished."
);
sender.sendMessage(
pref +
"/bingo conscript [player]" +
suff +
" adds [player] to the current bingo game, if it exists and has not yet finished."
);
sender.sendMessage(
pref +
"/bingo prolong [timeInSeconds]" +
suff +
" extends the duration of the current bingo game."
);
sender.sendMessage(
pref +
Expand Down
13 changes: 13 additions & 0 deletions src/BingoInventoryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.event.player.PlayerBucketFillEvent;

public class BingoInventoryHelper implements Listener {

Expand Down Expand Up @@ -126,6 +127,18 @@ public void invEvent6(PlayerSwapHandItemsEvent e) {
}
}

@EventHandler
public void onBucket(PlayerBucketFillEvent e) {
if (plugin.game == null || plugin.game.in_progress == false) {
return;
}
Player player = e.getPlayer();
BingoPlayer bplayer = this.plugin.game.get_player(player);
if (bplayer.goals_remaining.contains(e.getItemStack().getType())) {
find_goal(bplayer, e.getItemStack().getType());
}
}

public void find_goal(BingoPlayer bplayer, Material mat) {
bplayer.find(mat);
for (BingoPlayer bp : plugin.game.players) {
Expand Down
26 changes: 10 additions & 16 deletions src/BingoPlayer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
Expand Down Expand Up @@ -69,11 +71,18 @@ public void respawn() {
ItemStack tool;
ItemMeta meta;
PlayerInventory pinv=this.player.getInventory();
for (String item:this.plugin.getConfig().getStringList("initial-items-unbreakable")){
for (String item:this.plugin.getConfig().getConfigurationSection("initial-items-unbreakable").getKeys(false)){
tool=new ItemStack(Material.getMaterial(item.toUpperCase()));
meta=tool.getItemMeta();
meta.setUnbreakable(true);
tool.setItemMeta(meta);
if (this.plugin.getConfig().getConfigurationSection("initial-items-unbreakable." + item) != null) {
int level = this.plugin.getConfig().getInt("initial-items-unbreakable." + item + ".level");
String enchant = this.plugin.getConfig().getString("initial-items-unbreakable." + item + ".enchant");
if (Enchantment.getByKey(NamespacedKey.fromString(enchant)) != null) {
tool.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.fromString(enchant)), level);
}
}
if (tool==null){
this.plugin.log(item+" not recognized as valid material.");
} else {
Expand All @@ -88,21 +97,6 @@ public void respawn() {
pinv.addItem(tool);
}
}
/* tool=new ItemStack(Material.IRON_PICKAXE);
ItemMeta meta=tool.getItemMeta();
meta.setUnbreakable(true);
tool.setItemMeta(meta);
pinv.addItem(tool);
tool=new ItemStack(Material.IRON_AXE);
tool.getItemMeta().setUnbreakable(true);
pinv.addItem(tool);
tool=new ItemStack(Material.IRON_SHOVEL);
tool.getItemMeta().setUnbreakable(true);
pinv.addItem(tool);
this.player.getInventory().addItem(new ItemStack(Material.GOLDEN_CARROT, 64));*/
//this.player.getInventory().addItem(new ItemStack(Material.FURNACE,64));
//this.player.getInventory().addItem(new ItemStack(Material.COAL,64));
//this.player.getInventory().addItem(new ItemStack(Material.RAW_IRON,64));
if (this.map != null) {
this.player.getInventory().setItemInOffHand(this.map);
}
Expand Down
11 changes: 10 additions & 1 deletion src/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
1.1.5
Add /bingo conscript command, to allow for adding people who forget they have to join.
Add /bingo prolong to increase the duration of thegame mid-play
Fixed bug where milking a cow did not trigger the item collection detection function.
Added ability to put enchantments on tools, and put looting 3 on the axe and fortune 3 on the pick in the default config.
1.1.4
Add reminder when 5:00 and 1:00 remain. Optimize loading time when making new game.
Changed /bingo card to run even if a player has a map to help with bug where when
a player is killed and their map taken by another player, the respawning player will have the killer's card.
1.1.3
Fix bug where players would remain near spawn when isolatePlayers flag was set.
Fix bug where goals would non change until plugin was restarted.
Fix bug where goals would not change until plugin was restarted.
1.1.2
When clearInventories is set to true, achievements are also cleared.
1.1.1
Expand Down
4 changes: 4 additions & 0 deletions src/GameDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public void start(int time) {
this.timer = time;
this.score_counter = SCORE_COUNTER + 1;
}

public void prolong(int time) {
this.timer += time;
}
}
5 changes: 3 additions & 2 deletions src/GameHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public void give_map(BingoPlayer bplayer) {
);
return;
}
if (
/* if (
bplayer.getMap() != null &&
bplayer.getMap().equals(bplayer.player.getInventory().getItemInOffHand())
) {
bplayer.player.sendMessage("You already have your card. Forcing inventory update.");
bplayer.player.updateInventory();
return;
}
}*/
ItemStack item = new ItemStack(Material.FILLED_MAP);
MapView view = Bukkit.createMap(Bukkit.getWorlds().get(0));
view.getRenderers().forEach(view::removeRenderer);
Expand All @@ -37,6 +37,7 @@ public void give_map(BingoPlayer bplayer) {
view.setLocked(false);
MapMeta meta = (MapMeta) item.getItemMeta();
meta.setMapView(view);
meta.setDisplayName("§a" + bplayer.player.getName() + "'s bingo card§f");
item.setItemMeta(meta);
PlayerInventory inventory = bplayer.player.getInventory();
inventory.setItemInOffHand(item);
Expand Down
7 changes: 7 additions & 0 deletions src/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ public void end() {
plugin.game = null;
}

public void prolong(int seconds) {
plugin.daemon.prolong(seconds);
for (BingoPlayer bp : players) {
bp.player.sendMessage("Game duration prolonged by " + seconds);
}
}

public void record() {

}
Expand Down
25 changes: 20 additions & 5 deletions src/TODO
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
Support Earlier Games -- should work, just need to downgrade api and test

bug with health in tab not updating on respawn
bug with health in tab not updating on respawn only for self player

read map image bitmaps from file instead of in class
categories for armor/tools, and sea temple?

admin only for /bingo new?
admin only for /bingo new if ongoing game?

milk bucket
check integer args for times

on /top preserve pitch and yaw
"run it back" button

/bingo kick
/bingo roster

keepinv

freeze day/night option
put players in same biome?
put players in same biome?

teams?

totem, but if used has penalty

/bingo all [time]

rejoin, start with blocks
11 changes: 9 additions & 2 deletions src/TabAgent.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -7,6 +8,7 @@
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;

public class TabAgent implements Listener {

Expand Down Expand Up @@ -48,11 +50,16 @@ public void onJoinServer(PlayerJoinEvent e) {

@EventHandler
public void onRespawn(PlayerRespawnEvent e) {
updatePlayer(e.getPlayer(), 20);
if (plugin.game != null && plugin.game.get_player(e.getPlayer()) != null) {
e.setRespawnLocation(plugin.game.get_player(e.getPlayer()).getSpawn());
plugin.game.get_player(e.getPlayer()).respawn();
}
updatePlayer(e.getPlayer(), 20);
}

@EventHandler
public void onWorldTransition(PlayerChangedWorldEvent e) {
updatePlayer(e.getPlayer());
}

public void updatePlayer(Player player) {
Expand All @@ -79,7 +86,7 @@ public void updatePlayer(Player player) {
"§a" +
player.getName() +
" " +
health_str +
health_str + " " + ((player.getWorld().getEnvironment() == World.Environment.NORMAL) ? "§f" : ((player.getWorld().getEnvironment() == World.Environment.NETHER) ? "§4" : "§a")) + "☀" +
plugin.game.get_player_score(player)
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/TabCompletionManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
Expand All @@ -14,6 +16,7 @@ public TabCompletionManager(Main plugin) {
this.plugin = plugin;
root_args.add("new");
root_args.add("join");
root_args.add("conscript");
root_args.add("start");
root_args.add("card");
root_args.add("top");
Expand Down Expand Up @@ -89,6 +92,13 @@ public List<String> onTabComplete(
list.add("false");
return list;
}
if (args[0].equalsIgnoreCase("conscript")) {
for (Player player : Bukkit.getOnlinePlayers()) {
list.add(player.getDisplayName());
}
list.add("*");
return list;
}
}
return list;
}
Expand Down
Loading

0 comments on commit a87c3b5

Please sign in to comment.