-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shinixsensei
committed
Sep 11, 2021
1 parent
8303c72
commit 39d1a52
Showing
8 changed files
with
260 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
name: RIN | ||
main: dev.angelsflyinhell.rin.RIN | ||
author: angelsflyinhell | ||
version: 1.0.0 | ||
api-version: 1.14 | ||
version: 1.1.0 | ||
api-version: 1.14 | ||
commands: | ||
sethome: | ||
description: Save your current location as a Home Point. | ||
usage: /<command> <name> | ||
aliases: [ sh, seth, shome ] | ||
delhome: | ||
description: Delete a Home Point from your Home Point list. | ||
usage: /<command> <name> | ||
aliases: [ dh, del0h, dhome ] | ||
homes: | ||
description: View a list of all Home Points owned by you. | ||
usage: /<command> | ||
aliases: [hs, hlist, homel] | ||
home: | ||
description: Select a Home Point to teleport to. | ||
usage: /<command> <name> | ||
aliases: [ h, hp, tpH, teleportH, tpHome ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
package dev.angelsflyinhell.rin; | ||
|
||
import dev.angelsflyinhell.rin.events.BetterSaplings; | ||
import dev.angelsflyinhell.rin.plugins.BetterSaplings; | ||
import dev.angelsflyinhell.rin.plugins.QuickHomes; | ||
import dev.angelsflyinhell.rin.tools.ConsoleUtils; | ||
import dev.angelsflyinhell.rin.tools.RINConfig; | ||
import dev.angelsflyinhell.rin.tools.props.QHSave; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.util.Objects; | ||
|
||
public class RIN extends JavaPlugin { | ||
|
||
@Override | ||
public void onEnable() { | ||
getServer().getPluginManager().registerEvents(new BetterSaplings(), this); | ||
getServer().getConsoleSender().sendMessage( ChatColor.DARK_PURPLE + ConsoleUtils.PREFIX + "Loaded " + ConsoleUtils.FEATURES); | ||
RINConfig.init(); | ||
|
||
if(!RINConfig.propExist("bettersaplings") || Objects.equals(RINConfig.getValue("bettersaplings"), "true")) { | ||
getServer().getPluginManager().registerEvents(new BetterSaplings(), this); | ||
} | ||
|
||
if(!RINConfig.propExist("quickhomes") || Objects.equals(RINConfig.getValue("quickhomes"), "true")) { | ||
QHSave.init(); | ||
Objects.requireNonNull(getCommand("sethome")).setExecutor(new QuickHomes()); | ||
Objects.requireNonNull(getCommand("delhome")).setExecutor(new QuickHomes()); | ||
Objects.requireNonNull(getCommand("homes")).setExecutor(new QuickHomes()); | ||
Objects.requireNonNull(getCommand("home")).setExecutor(new QuickHomes()); | ||
} | ||
getServer().getConsoleSender().sendMessage( ChatColor.DARK_PURPLE + ConsoleUtils.PREFIX + "Plugin loaded!"); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
getServer().getConsoleSender().sendMessage(ChatColor.DARK_PURPLE + ConsoleUtils.PREFIX + "Unloaded " + ConsoleUtils.FEATURES); | ||
getServer().getConsoleSender().sendMessage(ChatColor.DARK_PURPLE + ConsoleUtils.PREFIX + "Plugin unloaded"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...sflyinhell/rin/events/BetterSaplings.java → ...flyinhell/rin/plugins/BetterSaplings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package dev.angelsflyinhell.rin.plugins; | ||
|
||
import dev.angelsflyinhell.rin.tools.ConsoleUtils; | ||
import dev.angelsflyinhell.rin.tools.RINConfig; | ||
import dev.angelsflyinhell.rin.tools.props.QHSave; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Objects; | ||
|
||
public class QuickHomes implements CommandExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (!(sender instanceof Player)) | ||
return true; | ||
|
||
Player player = (Player) sender; | ||
|
||
if (command.getName().equalsIgnoreCase("sethome")) { | ||
|
||
if (args[0].equals("")) { | ||
player.sendMessage(ConsoleUtils.PREFIX + "Home Point cannot be empty."); | ||
} | ||
|
||
int playerHomes = 0; | ||
for (int i = 0; i < QHSave.getKeySize(); i++) { | ||
String key = QHSave.properties.keySet().toArray()[i].toString(); | ||
if(key.startsWith(String.valueOf(player.getUniqueId()))) { | ||
playerHomes++; | ||
} | ||
} | ||
|
||
if (RINConfig.propExist("quickhomesLimit") && Integer.parseInt(RINConfig.getValue("quickhomesLimit"))<=playerHomes) { | ||
player.sendMessage(ConsoleUtils.PREFIX + "Home Point couldn't be set: Exceeds limit of " + RINConfig.getValue("quickhomesLimit")); | ||
return true; | ||
} | ||
|
||
String key = player.getUniqueId() + "home" + args[0]; | ||
String loc = player.getLocation().getX() + ";" + player.getLocation().getY() + ";" + player.getLocation().getZ() + ";" + player.getWorld().getName(); | ||
QHSave.addKey(key, loc); | ||
player.sendMessage(ConsoleUtils.PREFIX + "Set Home Point: " + args[0]); | ||
} | ||
|
||
if (command.getName().equalsIgnoreCase("delhomes")) { | ||
String key = player.getUniqueId() + "home" + args[0]; | ||
if (QHSave.propExist(key)) { | ||
QHSave.addKey(key, "DELETED"); | ||
player.sendMessage(ConsoleUtils.PREFIX + "Deleted Home Point: " + args[0]); | ||
} | ||
player.sendMessage(ConsoleUtils.PREFIX + "Couldn't find Home Point \"" + args[0] + "\""); | ||
} | ||
|
||
if (command.getName().equalsIgnoreCase("homes")) { | ||
player.sendMessage(ConsoleUtils.PREFIX + "Your Homes: "); | ||
for (int i = 0; i < QHSave.getKeySize(); i++) { | ||
String key = QHSave.properties.keySet().toArray()[i].toString(); | ||
if (key.startsWith(String.valueOf(player.getUniqueId()))) { | ||
String outKey = key.replace(player.getUniqueId() + "home", ""); | ||
player.sendMessage(ConsoleUtils.PREFIX + (i + 1) + ". " + outKey); | ||
} | ||
} | ||
} | ||
|
||
if (command.getName().equalsIgnoreCase("home")) { | ||
String key = player.getUniqueId() + "home" + args[0]; | ||
if (!QHSave.propExist(key) || Objects.equals(QHSave.getValue(key), "DELETED")) { | ||
player.sendMessage(ConsoleUtils.PREFIX + "Couldn't find Home Point \"" + args[0] + "\""); | ||
return true; | ||
} | ||
|
||
String[] s = QHSave.getValue(key).split(";"); | ||
Location loc = new Location(Bukkit.getWorld(s[3]), Double.parseDouble(s[0]), Double.parseDouble(s[1]), Double.parseDouble(s[2])); | ||
player.teleport(loc); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package dev.angelsflyinhell.rin.tools; | ||
|
||
import java.io.*; | ||
import java.util.Properties; | ||
|
||
public class RINConfig { | ||
private static Properties properties; | ||
static File file = new File("config.rin"); | ||
|
||
public static void init(){ | ||
properties = new Properties(); | ||
try { | ||
InputStream in = new FileInputStream(file); | ||
properties.load(in); | ||
} catch (IOException e) { | ||
fileNotFoundAction(file); | ||
} | ||
} | ||
|
||
public static boolean propExist(String key) { | ||
if (properties.getProperty(key) == null) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
public static String getValue(String key) { | ||
return properties.getProperty(key); | ||
} | ||
|
||
public static void addKey(String hash, String name) { | ||
properties.put(hash, name); | ||
try { | ||
properties.store(new FileOutputStream(file), "RIN Configuration"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void deleteKey(String hash) { | ||
properties.remove(hash); | ||
} | ||
|
||
private static void fileNotFoundAction(File f){ | ||
try { | ||
properties.store(new FileOutputStream(f), "RIN Configuration"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
init(); | ||
} | ||
|
||
public static int getKeySize() { | ||
return properties.size(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package dev.angelsflyinhell.rin.tools.props; | ||
|
||
import java.io.*; | ||
import java.util.Properties; | ||
|
||
public class QHSave { | ||
|
||
public static Properties properties; | ||
static File file = new File("quickhomes.rin"); | ||
|
||
public static void init(){ | ||
properties = new Properties(); | ||
try { | ||
InputStream in = new FileInputStream(file); | ||
properties.load(in); | ||
} catch (IOException e) { | ||
fileNotFoundAction(file); | ||
} | ||
} | ||
|
||
public static boolean propExist(String key) { | ||
if (properties.getProperty(key) == null) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
public static String getValue(String key) { | ||
return properties.getProperty(key); | ||
} | ||
|
||
public static void addKey(String hash, String name) { | ||
properties.put(hash, name); | ||
try { | ||
properties.store(new FileOutputStream(file), "quickhomes savefile"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void deleteKey(String hash) { | ||
properties.remove(hash); | ||
} | ||
|
||
private static void fileNotFoundAction(File f){ | ||
try { | ||
properties.store(new FileOutputStream(f), "quickhomes savefile"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
init(); | ||
} | ||
|
||
public static int getKeySize() { | ||
return properties.size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
name: RIN | ||
main: dev.angelsflyinhell.rin.RIN | ||
author: angelsflyinhell | ||
version: 1.0.0 | ||
api-version: 1.14 | ||
version: 1.1.0 | ||
api-version: 1.14 | ||
commands: | ||
sethome: | ||
description: Save your current location as a Home Point. | ||
usage: /<command> <name> | ||
aliases: [ sh, seth, shome ] | ||
delhome: | ||
description: Delete a Home Point from your Home Point list. | ||
usage: /<command> <name> | ||
aliases: [ dh, del0h, dhome ] | ||
homes: | ||
description: View a list of all Home Points owned by you. | ||
usage: /<command> | ||
aliases: [hs, hlist, homel] | ||
home: | ||
description: Select a Home Point to teleport to. | ||
usage: /<command> <name> | ||
aliases: [ h, hp, tpH, teleportH, tpHome ] |