Skip to content

Commit

Permalink
[add]アイアンゴーレムのスポーツを制御するコードを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
huda0209 committed May 2, 2021
1 parent 57a2f5b commit 51dbdcf
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.github.huda0209.irongolemspawncanceller.command;

import com.github.huda0209.irongolemspawncanceller.IronGolemSpawnCanceller;
import com.github.huda0209.irongolemspawncanceller.configload;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

public class commandHandler implements CommandExecutor {

private final IronGolemSpawnCanceller plugin;
public commandHandler(IronGolemSpawnCanceller pl){
this.plugin = pl;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
if(args.length==0) return false;
switch (args[0].toLowerCase(Locale.ROOT)){
case "setmode" :
if(!sender.hasPermission("IronGolemSpawnCanceller.SetMode")){
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c You don't have permission!");
return true;
}
if(args.length!=2){
return false;
}
if(!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")){
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c Please specify SetMode with true or false.");
return true;
}

Boolean mode = args[1].equalsIgnoreCase("true");

sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§a IronGolemSpawnCancellMode set to "+ mode.toString() +".");
configload.setIronGolemSpawnCancellMode(mode,plugin);
break;

case "reload":
if(!sender.hasPermission("IronGolemSpawnCanceller.Reload")){
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c You don't have permission!");
return true;
}
try {
configload.loadConfig(plugin);
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§a Reload the config file.");
}catch(Exception e){
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c While reload the config file, occurred error. Please check console.");
System.out.println(e.toString());
}
break;

default:
sender.sendMessage("§9[" + plugin.getDescription().getName() + "]§c Unknown command.");
break;
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.huda0209.irongolemspawncanceller;

import org.bukkit.configuration.Configuration;

public class configload {

public static Boolean IronGolemSpawnCancellMode = false;
private static Configuration config;

public static void loadConfig(IronGolemSpawnCanceller pl){
try{
config = pl.getConfig();
}catch (Exception exception){
System.out.println("While load the config file, occurred error.");
return;
}

IronGolemSpawnCancellMode = config.getBoolean("IronGolemSpawnCancellMode");
}

public static void setIronGolemSpawnCancellMode(Boolean bool,IronGolemSpawnCanceller pl){
IronGolemSpawnCancellMode = bool;
config.set("IronGolemSpawnCancellMode",bool);
pl.saveConfig();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.huda0209.irongolemspawncanceller.listener;

import com.github.huda0209.irongolemspawncanceller.IronGolemSpawnCanceller;
import com.github.huda0209.irongolemspawncanceller.configload;
import org.bukkit.entity.Entity;
import org.bukkit.entity.IronGolem;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;

public class IronGolemSpawnEvent implements Listener {

private final IronGolemSpawnCanceller plugin;
public IronGolemSpawnEvent(IronGolemSpawnCanceller pl) {
this.plugin = pl;
}

@EventHandler
public void IronGolemSpawnEvent(EntitySpawnEvent event){
Entity entity = event.getEntity();

if(!configload.IronGolemSpawnCancellMode) return;
if(!(entity instanceof IronGolem)) return;

IronGolem ig = (IronGolem) entity;

if(!ig.isPlayerCreated()) event.setCancelled(true);
System.out.println("[IronGolemSpawnCanceller]-------------------------------\nTo spawn IronGolem successful Cancelled.\n"+
"World : "+entity.getWorld().getName()+"\n"+
"Location: ("+entity.getLocation().getX()+", "+entity.getLocation().getY()+", "+entity.getLocation().getZ()+
"\n-------------------------------");
}
}
12 changes: 12 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# -------------------------------------------------------------
# | IronGolemSpawnCanceller |
# | |
# | Author : huda0209 |
# | Depend : |
# | GitHub : |
# |https://github.com/stella-server-mc/IronGolemSpawnCanceller|
# | ran by spigot 1.13 |
# -------------------------------------------------------------

IronGolemSpawnCancellMode: true
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ commands:
igsc:
description: IronGolemSpawnCanceller plugin command.
usage:
/<command> reload - join config.
/<command> reload - Reload config.\n
/<command> setmode [true/false] - set mode to spawn IronGolem.
permissions:
IronGolemSpawnCanceller.SetMode:
Expand Down

0 comments on commit 51dbdcf

Please sign in to comment.