Cloning things in
This commit is contained in:
parent
7a4107d790
commit
f1034a986f
14 changed files with 558 additions and 1 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
BIN
bin/.DS_Store
vendored
Normal file
BIN
bin/.DS_Store
vendored
Normal file
Binary file not shown.
0
config.yml
Normal file
0
config.yml
Normal file
10
plugin.yml
Normal file
10
plugin.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
main: iie.HelloWorldPlugin
|
||||||
|
version: 1.0.0
|
||||||
|
name: HelloWorldPlugin
|
||||||
|
commands:
|
||||||
|
hardcore:
|
||||||
|
description: Command that teleports you to hardcore world
|
||||||
|
HelloWorld:
|
||||||
|
description: Command that says Hello World!
|
||||||
|
debugRTP:
|
||||||
|
description: Command that randomly teleports someone inside the hardcore world
|
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
183
src/alisolarflare/RandomTP.java
Normal file
183
src/alisolarflare/RandomTP.java
Normal file
|
@ -0,0 +1,183 @@
|
||||||
|
package alisolarflare;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import iie.HelloWorldPlugin;
|
||||||
|
|
||||||
|
public class RandomTP implements CommandExecutor{
|
||||||
|
|
||||||
|
private int conflictX;
|
||||||
|
private int conflictZ;
|
||||||
|
private int conflictRadius = 70;
|
||||||
|
private boolean northUsed;
|
||||||
|
private boolean southUsed;
|
||||||
|
private boolean eastUsed;
|
||||||
|
private boolean westUsed;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private HelloWorldPlugin helloWorldPlugin;
|
||||||
|
public RandomTP(HelloWorldPlugin helloWorldPlugin) {
|
||||||
|
this.helloWorldPlugin = helloWorldPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
//every 4 players who use it will be teleported near each other.
|
||||||
|
//ex. iie > 1200, ali -> 1210, byz -> 1190, charles -> 1195, wind -> 300, zan -> 310, etc
|
||||||
|
public void conflictRtp(Player player, World world, Location minLocation, Location maxLocation){
|
||||||
|
//INIT - xDifference, xAverage
|
||||||
|
int xdifference = minLocation.getBlockX() - maxLocation.getBlockX();
|
||||||
|
int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2);
|
||||||
|
|
||||||
|
//INIT - zDifference, zAverage
|
||||||
|
int zdifference = minLocation.getBlockX() - maxLocation.getBlockY();
|
||||||
|
int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ());
|
||||||
|
|
||||||
|
//CHECK - Reset Cycle
|
||||||
|
if ((northUsed || southUsed || eastUsed || westUsed) == false){
|
||||||
|
|
||||||
|
//Tries 20 times to find a location
|
||||||
|
for(int i = 0; i < 20; i ++){
|
||||||
|
|
||||||
|
//INIT - attemptedX, attemptedZ
|
||||||
|
int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage;
|
||||||
|
int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage;
|
||||||
|
|
||||||
|
int cr = conflictRadius;
|
||||||
|
|
||||||
|
|
||||||
|
//CHECKS - if ground is safe
|
||||||
|
boolean groundIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER;
|
||||||
|
boolean northIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ-cr).getType() != Material.WATER;
|
||||||
|
boolean eastIsSafe = world.getHighestBlockAt(attemptedX+cr, attemptedZ).getType() != Material.WATER;
|
||||||
|
boolean southIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ+cr).getType() != Material.WATER;
|
||||||
|
boolean westIsSafe = world.getHighestBlockAt(attemptedX-cr, attemptedZ).getType() != Material.WATER;
|
||||||
|
|
||||||
|
//TRANSFER - data to class
|
||||||
|
if (groundIsSafe && (northIsSafe || southIsSafe || eastIsSafe || westIsSafe)){
|
||||||
|
|
||||||
|
northUsed = northIsSafe;
|
||||||
|
eastUsed = eastIsSafe;
|
||||||
|
westUsed = westIsSafe;
|
||||||
|
southUsed = southIsSafe;
|
||||||
|
conflictX = attemptedX;
|
||||||
|
conflictZ = attemptedZ;
|
||||||
|
|
||||||
|
player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String dir = "north";
|
||||||
|
//CHOOSES A RANDOM DIRECTION
|
||||||
|
for(int i = 0; i < 1000; i++){
|
||||||
|
double randomDirection = Math.random();
|
||||||
|
if (randomDirection < 0.25){
|
||||||
|
if(northUsed){
|
||||||
|
northUsed = true;
|
||||||
|
dir = "north";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else if(randomDirection < 0.50){
|
||||||
|
if(eastUsed){
|
||||||
|
eastUsed = true;
|
||||||
|
dir = "east";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else if(randomDirection < 0.75){
|
||||||
|
if(southUsed){
|
||||||
|
southUsed = true;
|
||||||
|
dir = "south";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(westUsed){
|
||||||
|
westUsed = true;
|
||||||
|
dir = "west";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TELEPORT - teleports player to the conflict point
|
||||||
|
switch(dir){
|
||||||
|
case "north":
|
||||||
|
northUsed = false;
|
||||||
|
player.teleport(world.getHighestBlockAt(conflictX, conflictZ - conflictRadius).getLocation());
|
||||||
|
break;
|
||||||
|
case "east":
|
||||||
|
eastUsed = false;
|
||||||
|
player.teleport(world.getHighestBlockAt(conflictX + conflictRadius, conflictZ).getLocation());
|
||||||
|
break;
|
||||||
|
case "south":
|
||||||
|
southUsed = false;
|
||||||
|
player.teleport(world.getHighestBlockAt(conflictX, conflictZ + conflictRadius).getLocation());
|
||||||
|
break;
|
||||||
|
case "west":
|
||||||
|
westUsed = false;
|
||||||
|
player.teleport(world.getHighestBlockAt(conflictX - conflictRadius, conflictZ).getLocation());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
player.teleport(world.getHighestBlockAt(conflictX, conflictZ).getLocation());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Randomly teleports a player, into the hardcore world
|
||||||
|
public void rtp(Player player, World world, Location minLocation, Location maxLocation){
|
||||||
|
player.sendMessage("TELEPORT INITIATED");
|
||||||
|
player.sendMessage("minLocation: " + minLocation.toString());
|
||||||
|
player.sendMessage("maxLocation: " + maxLocation.toString());
|
||||||
|
player.sendMessage("world : " + world.toString());
|
||||||
|
player.sendMessage("player : " + player.toString());
|
||||||
|
|
||||||
|
//INIT - xDifference, xAverage
|
||||||
|
int xdifference = minLocation.getBlockX() - maxLocation.getBlockX();
|
||||||
|
int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2);
|
||||||
|
|
||||||
|
//INIT - zDifference, zAverage
|
||||||
|
int zdifference = minLocation.getBlockX() - maxLocation.getBlockY();
|
||||||
|
int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ());
|
||||||
|
player.sendMessage("Averages : " + xAverage + "|" + zAverage);
|
||||||
|
//TELEPORTS - Tries 20 times to find a location
|
||||||
|
for(int i = 0; i < 20; i ++){
|
||||||
|
|
||||||
|
//INIT - attemptedX, attemptedZ
|
||||||
|
int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage;
|
||||||
|
int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage;
|
||||||
|
player.sendMessage("TAKE " + i + " : " + attemptedX + ", "+ attemptedZ);
|
||||||
|
//CHECKS - if ground is safe
|
||||||
|
boolean groundisSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER;
|
||||||
|
if (groundisSafe){
|
||||||
|
player.sendMessage("SAFE GROUND, TELEPORTING");
|
||||||
|
player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//player.teleport(arg0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if(!(sender instanceof Player)){
|
||||||
|
sender.sendMessage("You must be a Player to use this command!");
|
||||||
|
sender.sendMessage(sender.toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(player.getWorld().getName() != "hardcore"){
|
||||||
|
sender.sendMessage("You must be in the hardcore world to use this command!");
|
||||||
|
sender.sendMessage("Current World: " + player.getWorld().getName());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
rtp(player, player.getWorld(), new Location(player.getWorld(), 644, 65, -944), new Location(player.getWorld(), 1700, 65, 464));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
26
src/alisolarflare/listeners/CompassLobby.java
Normal file
26
src/alisolarflare/listeners/CompassLobby.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package alisolarflare.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
||||||
|
public class CompassLobby implements Listener{
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event){
|
||||||
|
openGUI(event.getPlayer());
|
||||||
|
}
|
||||||
|
public void openGUI(Player p){
|
||||||
|
//format: null, size of inventory (must be divisible by 9), "GUI name"
|
||||||
|
Inventory inv = Bukkit.createInventory(null, 9, "GUI Name");
|
||||||
|
inv.setItem(0, new ItemStack(Material.GRASS));
|
||||||
|
inv.setItem(1, new ItemStack(Material.IRON_SWORD));
|
||||||
|
inv.setItem(8, new ItemStack(Material.BARRIER));
|
||||||
|
p.openInventory(inv);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package alisolarflare.listeners;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.CraftItemEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class ConflictCompassCraftingListener implements Listener{
|
||||||
|
public static void main(String[] args){
|
||||||
|
String nulltest = null;
|
||||||
|
if(nulltest == null){
|
||||||
|
System.out.println("NUUUUULL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public boolean onConflictCompassCraft(CraftItemEvent event){
|
||||||
|
//SANITATION - HARDCORE
|
||||||
|
if(event.getWhoClicked().getWorld().getName() != "hardcore")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
//INIT - targetItem
|
||||||
|
ItemStack targetItem = event.getRecipe().getResult();
|
||||||
|
|
||||||
|
//SANITATION - NOT COMPASS
|
||||||
|
if(targetItem.getType() != Material.COMPASS)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
//GIVE - chainmail chestplate
|
||||||
|
event.getWhoClicked().getInventory().addItem(generateConflictCompass(event.getWhoClicked()));
|
||||||
|
//PLAY - cave sound
|
||||||
|
event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack generateConflictCompass(HumanEntity crafter) {
|
||||||
|
ItemStack conflictCompass = new ItemStack(Material.COMPASS);
|
||||||
|
conflictCompass.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
|
||||||
|
List<String> loreString = new ArrayList<String>();
|
||||||
|
loreString.add("The needle is tipped with the scent of");
|
||||||
|
|
||||||
|
loreString.add(nearestPlayerName(crafter));
|
||||||
|
conflictCompass.getItemMeta().setLore(loreString);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String nearestPlayerName(HumanEntity crafter) {
|
||||||
|
Player nearestPlayer = null;
|
||||||
|
for(Player player: crafter.getWorld().getPlayers()){
|
||||||
|
if (player.getUniqueId() == crafter.getUniqueId()){
|
||||||
|
//SKIP CODE
|
||||||
|
}if (nearestPlayer == null){
|
||||||
|
nearestPlayer = player;
|
||||||
|
}else if (nearestPlayer.getLocation().distance(crafter.getLocation()) > player.getLocation().distance(crafter.getLocation())){
|
||||||
|
nearestPlayer = player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(nearestPlayer == null)
|
||||||
|
return "METAL";
|
||||||
|
|
||||||
|
return nearestPlayer.toString();
|
||||||
|
}
|
||||||
|
}
|
51
src/alisolarflare/listeners/DiamondArmorBlocker.java
Normal file
51
src/alisolarflare/listeners/DiamondArmorBlocker.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package alisolarflare.listeners;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.CraftItemEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class DiamondArmorBlocker implements Listener{
|
||||||
|
public static List<Material> blockedItems = Arrays.asList(Material.DIAMOND_BOOTS, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_HELMET);
|
||||||
|
@EventHandler
|
||||||
|
public boolean onArmorSmith(CraftItemEvent event){
|
||||||
|
//SANITATION - hardcore
|
||||||
|
if(event.getWhoClicked().getWorld().getName() != "hardcore"){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//INIT - inventory, targetItem
|
||||||
|
ItemStack targetItem = event.getRecipe().getResult();
|
||||||
|
|
||||||
|
//REPLACE - Diamond Chestplate > Chainmail Chestplate
|
||||||
|
if (blockedItems.contains(targetItem.getType())){
|
||||||
|
event.setCancelled(true);
|
||||||
|
//GIVE - chainmail chestplate
|
||||||
|
event.getWhoClicked().getInventory().addItem(failArmor(targetItem.getType()));
|
||||||
|
//PLAY - cave sound
|
||||||
|
event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0);
|
||||||
|
event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.ENTITY_ITEM_BREAK,0,0);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public ItemStack failArmor(Material material){
|
||||||
|
ItemStack failArmor = new ItemStack(material);
|
||||||
|
failArmor.addEnchantment(Enchantment.THORNS, 1);
|
||||||
|
|
||||||
|
//INIT - Chainmail's lore
|
||||||
|
List<String> loreString = new ArrayList<String>();
|
||||||
|
loreString.add("This world is forever dangerous.");
|
||||||
|
loreString.add("There is no protection here.");
|
||||||
|
failArmor.getItemMeta().setLore(loreString);
|
||||||
|
return failArmor;
|
||||||
|
}
|
||||||
|
}
|
43
src/iie/DeathListener.java
Normal file
43
src/iie/DeathListener.java
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package iie;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
|
||||||
|
public class DeathListener implements Listener {
|
||||||
|
|
||||||
|
HelloWorldPlugin plugin;
|
||||||
|
public DeathListener(HelloWorldPlugin plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onHardcoreDeath(PlayerDeathEvent deathEvent){
|
||||||
|
|
||||||
|
int currentTime = (int) ((System.currentTimeMillis())/1000); //divided by 1000 to fit within Integer range
|
||||||
|
Player player = deathEvent.getEntity();
|
||||||
|
String playername = (String) player.getName();
|
||||||
|
Location location = player.getLocation();
|
||||||
|
String worldString = (String) location.getWorld().getName();
|
||||||
|
|
||||||
|
//player.sendMessage("you died");
|
||||||
|
//player.sendMessage("currentTime = " + String.valueOf(currentTime));
|
||||||
|
//player.sendMessage("worldString = " + String.valueOf(worldString));
|
||||||
|
|
||||||
|
if (Objects.equals(worldString, "hardcore")){
|
||||||
|
|
||||||
|
HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(currentTime);
|
||||||
|
HelloWorldPlugin.hardcoreInvite.getScore(playername).setScore(0);
|
||||||
|
|
||||||
|
//player.sendMessage("death detected");
|
||||||
|
//player.sendMessage("hardcoreTimeDead score = " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore()));
|
||||||
|
//player.sendMessage("currentTime = " + String.valueOf(currentTime));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
75
src/iie/HelloWorld.java
Normal file
75
src/iie/HelloWorld.java
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
package iie;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
public class HelloWorld implements CommandExecutor {
|
||||||
|
|
||||||
|
HelloWorldPlugin plugin;
|
||||||
|
public HelloWorld(HelloWorldPlugin plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command label, String command, String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (sender instanceof Player){
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String playername = sender.getName();
|
||||||
|
|
||||||
|
if (!Objects.equals(player.getScoreboard(), Bukkit.getScoreboardManager().getMainScoreboard())){
|
||||||
|
player.sendMessage("not in your current circumstances");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
World hardcoreWorld = player.getServer().getWorld("hardcore");
|
||||||
|
Location location = new Location(hardcoreWorld, 1280, 71, -179);
|
||||||
|
|
||||||
|
int currentTime = (int) ((System.currentTimeMillis())/1000);
|
||||||
|
int deathTime = 0;
|
||||||
|
|
||||||
|
if (HelloWorldPlugin.hardcoreTimeDead.getScore(playername) != null) //null check - if score exists
|
||||||
|
deathTime = HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore(); //set deathTime to that score
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (currentTime - deathTime >= 86400 && deathTime != 0){
|
||||||
|
sender.sendMessage("You died " + ((currentTime - deathTime) /3600) + " hours ago. Good luck, " + playername + ".");
|
||||||
|
player.teleport(location);
|
||||||
|
player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,1F,1F);
|
||||||
|
}else if(deathTime == 0){
|
||||||
|
sender.sendMessage("You have never died, good luck");
|
||||||
|
player.teleport(location);
|
||||||
|
player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,1F,1F);
|
||||||
|
}else{
|
||||||
|
sender.sendMessage("you are dead for the next " + ((86400 - (currentTime - deathTime)) /3600) + " hours");
|
||||||
|
player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,1F,1F);
|
||||||
|
// replace sound with some other sound
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
sender.sendMessage("You must be a player to use this command!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
src/iie/HelloWorldPlugin.java
Normal file
43
src/iie/HelloWorldPlugin.java
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package iie;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scoreboard.Objective;
|
||||||
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
|
|
||||||
|
|
||||||
|
public class HelloWorldPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
public static Scoreboard board;
|
||||||
|
public static Objective hardcoreTimeDead;
|
||||||
|
public static Objective hardcoreInvite;
|
||||||
|
public static AbstractMap<String,String> deathMap = new HashMap<String,String>();
|
||||||
|
|
||||||
|
public void onEnable(){
|
||||||
|
|
||||||
|
board = Bukkit.getServer().getScoreboardManager().getMainScoreboard();
|
||||||
|
if (board.getObjective("hardcoreTimeDead") != null){ //null check hardcoreTimeDead
|
||||||
|
hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
|
||||||
|
}else{
|
||||||
|
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
|
||||||
|
}
|
||||||
|
if (board.getObjective("hardcoreInvite") != null){ //null check hardcoreInvite
|
||||||
|
hardcoreInvite = board.getObjective("hardcoreInvite");
|
||||||
|
}else{
|
||||||
|
hardcoreInvite = board.registerNewObjective("hardcoreInvite", "dummy");
|
||||||
|
}
|
||||||
|
|
||||||
|
registerCommands();
|
||||||
|
getServer().getPluginManager().registerEvents(new JoinListener(this), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public void registerCommands(){
|
||||||
|
getCommand("hardcore").setExecutor(new HelloWorld(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/iie/JoinListener.java
Normal file
52
src/iie/JoinListener.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package iie;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
public class JoinListener implements Listener {
|
||||||
|
|
||||||
|
HelloWorldPlugin plugin;
|
||||||
|
public JoinListener(HelloWorldPlugin plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent JoinEvent){
|
||||||
|
|
||||||
|
|
||||||
|
Player player = JoinEvent.getPlayer();
|
||||||
|
String playername = (String) player.getName();
|
||||||
|
|
||||||
|
|
||||||
|
if (HelloWorldPlugin.hardcoreInvite.getScore(playername) == null){ //null check
|
||||||
|
HelloWorldPlugin.hardcoreInvite.getScore(playername).setScore(0); //convert null to 0
|
||||||
|
}
|
||||||
|
if (HelloWorldPlugin.hardcoreTimeDead.getScore(playername) == null){ //null check
|
||||||
|
HelloWorldPlugin.hardcoreTimeDead.getScore(playername).setScore(0); //convert null to 0
|
||||||
|
}
|
||||||
|
|
||||||
|
int invite = HelloWorldPlugin.hardcoreInvite.getScore(playername).getScore();
|
||||||
|
int deathTime = HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore();
|
||||||
|
int currentTime = (int) ((System.currentTimeMillis())/1000);
|
||||||
|
|
||||||
|
|
||||||
|
if (currentTime - deathTime >= 86400 && deathTime != 0 && invite == 0){
|
||||||
|
player.sendMessage(playername + ", your death has lifted in Hardcore world. (You died " + String.valueOf((currentTime - deathTime) /3600) + " hours ago)");
|
||||||
|
player.sendMessage("Are you ready to give life another shot?");
|
||||||
|
HelloWorldPlugin.hardcoreInvite.getScore(playername).setScore(1);
|
||||||
|
}else if (currentTime - deathTime <= 86400){
|
||||||
|
player.sendMessage(String.valueOf((86400 - (currentTime - deathTime)) /3600) + " hours of death remaining in hardcore");
|
||||||
|
}else if (deathTime == 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//HelloWorldPlugin.deathMap.put(playername, String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore()));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue