shop and grappling hook

This commit is contained in:
Super_ 2020-01-07 15:13:59 -05:00
parent 3b715fc091
commit fbcb6da30d
7 changed files with 322 additions and 14 deletions

View File

@ -1,25 +1,16 @@
package me.totalfreedom.totalfreedommod.blocking;
import com.sk89q.worldedit.command.util.CreatureButcher;
import java.util.Arrays;
import java.util.List;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartCommandWatcher;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.block.ShulkerBox;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -29,7 +20,6 @@ import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityCombustEvent;
@ -41,8 +31,6 @@ import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
public class EventBlocker extends FreedomService
{
@ -162,12 +150,17 @@ public class EventBlocker extends FreedomService
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerDropItem(PlayerDropItemEvent event)
{
if (!plugin.al.isAdmin(event.getPlayer()))
{
event.setCancelled(true);
}
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
{
return;
}
if (event.getPlayer().getWorld().getEntities().size() > 750 && !plugin.al.isAdmin(event.getPlayer()))
if (event.getPlayer().getWorld().getEntities().size() > 750)
{
event.setCancelled(true);
}

View File

@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command;
import java.util.HashMap;
import java.util.Map;
import java.util.TimerTask;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
@ -19,6 +20,12 @@ public class Command_ride extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
if (fPlayer.getCageData().isCaged())
{
msg("You cannot used this command while caged.");
return true;
}
if (args.length < 1)
{

View File

@ -0,0 +1,101 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopData;
import me.totalfreedom.totalfreedommod.shop.ShopItem;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Access the shop", usage = "/<command> <buy> <item>")
public class Command_shop extends FreedomCommand
{
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!ConfigEntry.SHOP_ENABLED.getBoolean())
{
msg("The shop is currently disabled!", ChatColor.RED);
return true;
}
final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
ShopData sd = plugin.sh.getData(playerSender);
if (args.length == 0)
{
msg(prefix + ChatColor.GREEN + "Balance: " + ChatColor.RED + sd.getCoins());
return true;
}
if (args.length != 2)
{
return false;
}
switch (args[0])
{
case "buy":
{
ShopItem item = ShopItem.findItem(args[1]);
if (item == null)
{
msg("Invalid item: " + item);
return true;
}
if (sd.hasItem(item))
{
msg(prefix + ChatColor.GREEN + "You already have that item! To get it, use " + ChatColor.RED + "/shop get " + item.name() + ChatColor.GREEN + "!");
return true;
}
if (item.getCost() > sd.getCoins())
{
msg(prefix + ChatColor.GREEN + "You don't have enough money for this item!");
return true;
}
String signature = sd.giveItem(item);
sd.setCoins(sd.getCoins() - item.getCost());
plugin.sh.save(sd);
ItemStack stack = new ItemStack(item.getMaterial(), 1);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(item.getColoredName());
List<String> lore = new ArrayList<>();
lore.add(ChatColor.DARK_GRAY + signature);
meta.setLore(lore);
stack.setItemMeta(meta);
Inventory inv = playerSender.getInventory();
inv.setItem(inv.firstEmpty(), stack);
msg(prefix + ChatColor.GREEN + "You bought a " + item.getColoredName() + ChatColor.GREEN + "!");
return true;
}
case "get":
{
ShopItem item = ShopItem.findItem(args[1]);
if (item == null)
{
msg("Invalid item: " + item);
return true;
}
if (!sd.hasItem(item))
{
msg(prefix + ChatColor.GREEN + "You don't have that item! To buy iy, use " + ChatColor.RED + "/shop buy " + item.name() + ChatColor.GREEN + "!");
return true;
}
Inventory inv = playerSender.getInventory();
inv.setItem(inv.firstEmpty(), sd.getItem(item));
msg(prefix + ChatColor.GREEN + "You got your " + item.getColoredName() + ChatColor.GREEN + "!");
return true;
}
default:
{
return false;
}
}
}
}

View File

@ -7,8 +7,10 @@ import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.shop.ShopData;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.ProjectileHitEvent;
@ -21,7 +23,11 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
@ -310,4 +316,94 @@ public class ItemFun extends FreedomService
return min + (random.nextDouble() * ((max - min) + 1.0));
}
@EventHandler
public void onFish(PlayerFishEvent event)
{
Player player = event.getPlayer();
ShopData sd = plugin.sh.getData(player);
PlayerInventory inv = event.getPlayer().getInventory();
ItemStack rod = inv.getItemInMainHand();
if (rod.getType() == Material.FISHING_ROD) // just to make sure it is this hand that has the rod
{
if (rod.hasItemMeta())
{
ItemMeta meta = rod.getItemMeta();
if (meta.hasDisplayName())
{
if (meta.getDisplayName().contains("Grappling Hook"))
{
if (!meta.hasLore())
{
return;
}
for (String item : sd.getItems())
{
if (!meta.getLore().contains(ChatColor.DARK_GRAY + item))
{
return;
}
}
if (event.getState() == PlayerFishEvent.State.REEL_IN || event.getState() == PlayerFishEvent.State.IN_GROUND)
{
double orientation = player.getLocation().getYaw();
if (orientation < 0.0)
{
orientation += 360;
}
int speed = 5;
if (player.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.AIR)
{
speed = 15;
}
double xVel = 0;
double yVel = 1;
double zVel = 0;
if (orientation >= 0.0 && orientation < 22.5)
{
zVel = speed;
}
else if (orientation >= 22.5 && orientation < 67.5)
{
xVel = -(speed / 2.0);
zVel = speed / 2.0;
}
else if (orientation >= 67.5 && orientation < 112.5)
{
xVel = -speed;
}
else if (orientation >= 112.5 && orientation < 157.5)
{
xVel = -(speed / 2.0);
zVel = -(speed / 2.0);
}
else if (orientation >= 157.5 && orientation < 202.5)
{
zVel = -speed;
}
else if (orientation >= 202.5 && orientation < 247.5)
{
xVel = speed / 2.0;
zVel = -(speed / 2.0);
}
else if (orientation >= 247.5 && orientation < 292.5)
{
xVel = speed;
}
else if (orientation >= 292.5 && orientation < 337.5)
{
xVel = speed / 2.0;
zVel = speed / 2.0;
}
else if (orientation >= 337.5 && orientation < 360.0)
{
zVel = speed;
}
player.setVelocity(new Vector(xVel, yVel, zVel));
}
}
}
}
}
}
}

View File

@ -1,16 +1,21 @@
package me.totalfreedom.totalfreedommod.shop;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.base.ConfigLoadable;
import net.pravian.aero.base.ConfigSavable;
import net.pravian.aero.base.Validatable;
import org.apache.commons.lang3.Validate;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
{
@ -22,6 +27,7 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
@Getter
@Setter
private int coins;
private List<String> items = Lists.newArrayList();
public ShopData(Player player)
{
@ -40,6 +46,7 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
this.ips.clear();
this.ips.addAll(cs.getStringList("ips"));
this.coins = cs.getInt("coins", coins);
this.items.addAll(cs.getStringList("items"));
}
@Override
@ -49,6 +56,7 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
cs.set("username", username);
cs.set("ips", ips);
cs.set("coins", coins);
cs.set("items", items);
}
public List<String> getIps()
@ -67,6 +75,55 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
return ips.remove(ip);
}
public List<String> getItems()
{
return Collections.unmodifiableList(items);
}
public String giveItem(ShopItem item)
{
String signature = String.valueOf(item.getId());
for (int i = 0; i < 7; i++)
{
signature += FUtil.getRandomCharacter();
}
items.add(signature);
return signature;
}
public boolean hasItem(ShopItem item)
{
for (String i : items)
{
int id = Integer.valueOf(i.substring(0, 1));
if (item.getId() == id)
{
return true;
}
}
return false;
}
public ItemStack getItem(ShopItem item)
{
String signature = "";
for (String i : items)
{
int id = Integer.valueOf(i.substring(0, 1));
if (item.getId() == id)
{
signature = i;
}
}
ItemStack stack = new ItemStack(item.getMaterial(), 1);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(item.getColoredName());
List<String> lore = new ArrayList<>();
lore.add(ChatColor.DARK_GRAY + signature);
meta.setLore(lore);
stack.setItemMeta(meta);
return stack;
}
@Override
public boolean isValid()

View File

@ -0,0 +1,48 @@
package me.totalfreedom.totalfreedommod.shop;
import lombok.Getter;
import org.bukkit.ChatColor;
import org.bukkit.Material;
public enum ShopItem
{
GRAPPLING_HOOK("Grappling Hook", Material.FISHING_ROD, 100, ChatColor.GREEN, 0);
@Getter
private final String name;
@Getter
private final Material material;
@Getter
private final int cost;
@Getter
private final ChatColor color;
@Getter
private final int id;
ShopItem(String name, Material material, int cost, ChatColor color, int id)
{
this.name = name;
this.material = material;
this.cost = cost;
this.color = color;
this.id = id;
}
public String getColoredName()
{
return color + name;
}
public static ShopItem findItem(String string)
{
try
{
return ShopItem.valueOf(string.toUpperCase());
}
catch (Exception ignored)
{
}
return null;
}
}

View File

@ -56,6 +56,7 @@ public class FUtil
ChatColor.DARK_PURPLE,
ChatColor.LIGHT_PURPLE);
private static Iterator<ChatColor> CHAT_COLOR_ITERATOR;
private static String CHARACTER_STRING = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static
{
@ -488,4 +489,9 @@ public class FUtil
}
}
}
public static char getRandomCharacter()
{
return CHARACTER_STRING.charAt(new Random().nextInt(CHARACTER_STRING.length()));
}
}