Skip to content

Commit

Permalink
Добавлены новые события:
Browse files Browse the repository at this point in the history
"SetNight" (включить ночь), "SetDay" (включить день), "GiveIronSet" (выдать сет железной брони), "GiveIronSword" (выдать железнsй меч), "GiveDiamondSet" (выдать сет алмазной брони), "GiveDiamondSword" (выдать алмазный меч), "SpawnTamedDog" (заспавнить прирученного волка), "SpawnTamedCat" (заспавнить прирученного кота), "HealPlayer" (полностью вылечить игрока)
  • Loading branch information
link1107 committed Feb 10, 2022
1 parent 537ed7e commit 606c7d7
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>IgorLink</groupId>
<artifactId>DonationExecutor</artifactId>
<version>0.3.2-SNAPSHOT</version>
<version>0.3.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>DonationExecutor</name>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/igorlink/donationexecutor/DonationExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import igorlink.donationexecutor.executionsstaff.giantmobs.GiantMobManager;
import igorlink.donationexecutor.playersmanagement.StreamerPlayersManager;
import igorlink.service.MainConfig;
import igorlink.service.Utils;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import static igorlink.service.Utils.*;
Expand All @@ -29,10 +30,10 @@ public void onEnable() {
streamerPlayersManager = new StreamerPlayersManager();
giantMobManager = new GiantMobManager(this);
new DonationExecutorCommand();
Utils.fillTheSynonimousCharsHashMap();
}

ShitToInventory shitCommand = new ShitToInventory();
logToConsole(shitCommand.getName());

Bukkit.getPluginManager().registerEvents(new GeneralEventListener(),this);

}
Expand Down
104 changes: 79 additions & 25 deletions src/main/java/igorlink/donationexecutor/Executor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package igorlink.donationexecutor;

import igorlink.donationexecutor.executionsstaff.ExecUtils;
import igorlink.service.MainConfig;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -19,14 +20,16 @@
import static igorlink.service.Utils.*;
import static java.lang.Math.random;
import static java.lang.Math.round;
import static org.bukkit.Bukkit.getPlayer;
import static org.bukkit.Bukkit.getPlayerExact;

public class Executor {
public static String nameOfStreamerPlayer;
public static String nameOfSecondStreamerPlayer;
public static List<String> executionsNamesList = new ArrayList<>(Arrays.asList("ShitToInventory", "Lesch", "DropActiveItem",
"PowerKick", "ClearLastDeathDrop", "SpawnCreeper", "GiveDiamonds", "GiveStackOfDiamonds", "GiveBread",
"CallNKVD", "CallStalin", "RandomChange", "TamedBecomesEnemies", "HalfHeart", "BigBoom", "Nekoglai"));
"CallNKVD", "CallStalin", "RandomChange", "TamedBecomesEnemies", "HalfHeart", "BigBoom", "Nekoglai", "SetNight", "SetDay", "GiveIronSet",
"GiveIronSword", "GiveDiamondSet", "GiveDiamondSword", "SpawnTamedDog", "SpawnTamedCat", "HealPlayer"));



Expand Down Expand Up @@ -77,6 +80,15 @@ public static void DoExecute(String streamerName, String donationUsername, Strin
case "HalfHeart" -> halfHeart(streamerPlayer, validDonationUsername);
case "BigBoom" -> bigBoom(streamerPlayer, validDonationUsername);
case "Nekoglai" -> nekoglai(streamerPlayer, validDonationUsername);
case "SetDay" -> setDay(streamerPlayer, validDonationUsername);
case "SetNight" -> setNight(streamerPlayer, validDonationUsername);
case "GiveIronSet" -> giveIronSet(streamerPlayer, validDonationUsername);
case "GiveIronSword" -> giveIronSword(streamerPlayer, validDonationUsername);
case "GiveDiamondSet" -> giveDiamondSet(streamerPlayer, validDonationUsername);
case "GiveDiamondSword" -> giveDiamondSword(streamerPlayer, validDonationUsername);
case "SpawnTamedDog" -> spawnTamedDog(streamerPlayer, donationUsername);
case "SpawnTamedCat" -> spawnTamedCat(streamerPlayer, donationUsername);
case "HealPlayer" -> healPlayer(streamerPlayer, donationUsername);
}

}
Expand Down Expand Up @@ -175,35 +187,17 @@ public static void spawnCreeper (Player player, String donationUsername) {
public static void giveDiamonds (Player player, String donationUsername) {
//Give some diamonds to the player
announce(donationUsername, "насыпал тебе алмазов!", "насыпал алмазов", player, true);
Material itemType = Material.DIAMOND;
ItemStack itemStack = new ItemStack(itemType, MainConfig.diamondsAmount);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName("§bАлмаз");
meta.setLore(List.of("§7Эти алмазы подарил §f" + donationUsername));
itemStack.setItemMeta(meta);
player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
ExecUtils.giveToPlayer(player, Material.DIAMOND, 4, donationUsername);
}

public static void giveStackOfDiamonds (Player player, String donationUsername) {
announce(donationUsername, "насыпал тебе алмазов!", "насыпал алмазов", player, true);
Material itemType = Material.DIAMOND;
ItemStack itemStack = new ItemStack(itemType, 64);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName("§bАлмаз");
meta.setLore(Arrays.asList("§7Эти алмазы подарил §f" + donationUsername));
itemStack.setItemMeta(meta);
player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
ExecUtils.giveToPlayer(player, Material.DIAMOND, 64, donationUsername);
}

public static void giveBread (Player player, String donationUsername) {
announce(donationUsername, "дал тебе хлеба!", "дал хлеба", player, true);
Material itemType = Material.BREAD;
ItemStack itemStack = new ItemStack(itemType, 4);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName("§bХлеб");
meta.setLore(Arrays.asList("§7Этот хлеб подарил §f" + donationUsername));
itemStack.setItemMeta(meta);
Item bread = player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
announce(donationUsername, "дал тебе Советского Хлеба!", "дал Советского Хлеба", player, true);
ExecUtils.giveToPlayer(player, Material.BREAD, 4, donationUsername, "§6Советский Хлеб");
}

public static void callNKVD (Player player, String donationUsername) {
Expand All @@ -219,8 +213,10 @@ public static void callNKVD (Player player, String donationUsername) {
newloc.add(newdir);
nkvdMob = (LivingEntity) player.getWorld().spawnEntity(newloc, EntityType.ZOMBIE);
nkvdMob.setCustomName("§cСотрудник НКВД");
nkvdMob.getEquipment().setItem(EquipmentSlot.HAND, new ItemStack(Material.IRON_SWORD));
nkvdMob.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.3);
nkvdMob.getEquipment().setItem(EquipmentSlot.HAND, new ItemStack(Material.WOODEN_SWORD));
if (((Zombie) nkvdMob).isAdult()) {
nkvdMob.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.28);
}
}

}
Expand Down Expand Up @@ -301,5 +297,63 @@ public static void bigBoom (Player player, String donationUsername) {

}

public static void setNight (Player player, String donationUsername) {
announce(donationUsername, "включил на сервере ночь!", "включил ночь ради", player, true);
player.getWorld().setTime(18000);
}

public static void setDay (Player player, String donationUsername) {
announce(donationUsername, "включил на сервере день!", "включил день ради", player, true);
player.getWorld().setTime(6000);
}

public static void giveIronSet (Player player, String donationUsername) {
announce(donationUsername, "дал тебе железную броню!", "дал железную броню", player, true);
ExecUtils.giveToPlayer(player, Material.IRON_HELMET, 1, donationUsername);
ExecUtils.giveToPlayer(player, Material.IRON_BOOTS, 1, donationUsername);
ExecUtils.giveToPlayer(player, Material.IRON_CHESTPLATE, 1, donationUsername);
ExecUtils.giveToPlayer(player, Material.IRON_LEGGINGS, 1, donationUsername);
}

public static void giveIronSword (Player player, String donationUsername) {
announce(donationUsername, "дал тебе железный меч!", "дал железный меч", player, true);
ExecUtils.giveToPlayer(player, Material.IRON_SWORD, 1, donationUsername);
}

public static void giveDiamondSet (Player player, String donationUsername) {
announce(donationUsername, "дал тебе алмазную броню!", "дал алмазную броню", player, true);
ExecUtils.giveToPlayer(player, Material.DIAMOND_HELMET, 1, donationUsername);
ExecUtils.giveToPlayer(player, Material.DIAMOND_BOOTS, 1, donationUsername);
ExecUtils.giveToPlayer(player, Material.DIAMOND_CHESTPLATE, 1, donationUsername);
ExecUtils.giveToPlayer(player, Material.DIAMOND_LEGGINGS, 1, donationUsername);
}

public static void giveDiamondSword (Player player, String donationUsername) {
announce(donationUsername, "дал тебе алмазный меч!", "дал алмазный меч", player, true);
ExecUtils.giveToPlayer(player, Material.DIAMOND_SWORD, 1, donationUsername);
}

public static void spawnTamedDog (Player player, String donationUsername) {
announce(donationUsername, "подарил тебе дружка!", "подарил щенка", player, true);
Entity wolf = player.getWorld().spawnEntity(player.getLocation(), EntityType.WOLF);
((Wolf) wolf).setTamed(true);
((Wolf) wolf).setOwner(player);
((Wolf) wolf).setRemoveWhenFarAway(false);
wolf.setCustomName(donationUsername);
}

public static void spawnTamedCat (Player player, String donationUsername) {
announce(donationUsername, "подарил тебе котейку!", "подарил котейку", player, true);
Entity cat = player.getWorld().spawnEntity(player.getLocation(), EntityType.CAT);
((Cat) cat).setTamed(true);
((Cat) cat).setOwner(player);
((Cat) cat).setRemoveWhenFarAway(false);
cat.setCustomName(donationUsername);
}

public static void healPlayer (Player player, String donationUsername) {
announce(donationUsername, "подарил тебе котейку!", "подарил котейку", player, true);
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package igorlink.donationexecutor.executionsstaff;

import igorlink.service.MainConfig;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class ExecUtils {

public static void giveToPlayer(Player player, Material material, int amount, String donationUsername, String itemName) {
ItemStack itemStack = new ItemStack(material, amount);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(itemName);
meta.setLore(List.of("§7Подарочек от §e" + donationUsername));
itemStack.setItemMeta(meta);
player.getWorld().dropItemNaturally(player.getLocation().clone().add(player.getLocation().getDirection().setY(0).normalize()), itemStack);
}

public static void giveToPlayer(Player player, Material material, int amount, String donationUsername) {
ItemStack itemStack = new ItemStack(material, amount);
ItemMeta meta = itemStack.getItemMeta();
meta.setLore(List.of("§7Подарочек от §e" + donationUsername));
itemStack.setItemMeta(meta);
player.getWorld().dropItemNaturally(player.getLocation().clone().add(player.getLocation().getDirection().setY(0).normalize()), itemStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package igorlink.donationexecutor.playersmanagement;

import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
import igorlink.donationexecutor.playersmanagement.donationalerts.DonationAlertsToken;
import igorlink.donationexecutor.DonationExecutor;
import igorlink.donationexecutor.Executor;
Expand Down Expand Up @@ -102,6 +103,7 @@ private void onPlayerDeath(PlayerDeathEvent event) {
event.getDrops().clear();
thisStreamerPlayer.setDeathDrop(deathDrop);
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ public void reload() throws InterruptedException {
for (DonationAlertsToken token : listOfDonationAlertsTokens) {
token.disconnect();
}
Thread.sleep(1000);
listOfDonationAlertsTokens.clear();
getTokensFromConfig();
new BukkitRunnable() {
@Override
public void run() {
listOfDonationAlertsTokens.clear();
getTokensFromConfig();
}
}.runTaskLater(DonationExecutor.getInstance(), 20);

}

public void stop() throws InterruptedException {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/igorlink/service/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class Utils {
private static Boolean _isPluginActive = true;
protected static HashMap<Character, List<Character>> mapOfSynonimousChars = new HashMap<>();

//Вывод сообщения в консоль
public static void logToConsole(String text){
Expand Down Expand Up @@ -103,9 +104,7 @@ public static String cutOffKopeykis(String donationAmountWithKopeykis) {
return amountWithoutKopeykis.toString();
}

public static Boolean isBlackListed(String text) {
HashMap<Character, List<Character>> mapOfSynonimousChars = new HashMap<>();

public static void fillTheSynonimousCharsHashMap() {
mapOfSynonimousChars.put('h', (Arrays.asList('x', 'х', 'н', 'n'))); //eng
mapOfSynonimousChars.put('n', (Arrays.asList('н', 'й', 'и'))); //eng
mapOfSynonimousChars.put('н', (Arrays.asList('h', 'n', 'й', 'и'))); //rus
Expand Down Expand Up @@ -144,7 +143,9 @@ public static Boolean isBlackListed(String text) {
mapOfSynonimousChars.put('4', (Arrays.asList('ч')));
mapOfSynonimousChars.put('5', (Arrays.asList('с', 'c', 's')));
mapOfSynonimousChars.put('9', (Arrays.asList('r', 'я')));
}

public static Boolean isBlackListed(String text) {

String validationText = text.toLowerCase();

Expand Down
Loading

0 comments on commit 606c7d7

Please sign in to comment.